获取天气预报API
sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频)
https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campaign=commission&utm_source=cp-400000000398149&utm_medium=share

执行结果

详细参数
city #城市信息
cod #内部参数
cnt #预测天数
list #信息列表,主要获取weatherData---weather---main和description信息
message #内部参数

# -*- coding: utf-8 -*-
#! python3
# quickWeather.py - Prints the current weather for a location from the command line.
"""
Created on Sat Apr 16 10:24:28 2016 @author: daxiong
""" import json, requests, sys '''
# Compute location from command line arguments.
if len(sys.argv) < 2:
print('Usage: quickWeather.py location')
sys.exit()
location = ' '.join(sys.argv[1:])
'''
#城市名称
cityName="Chongqing"
#城市ID号
cityID="1814905"
#我的免费appID
appID="0383ae59663e14ab5a6855d5b6ad5d00"
#获取天气天数
days="3"
# Download the JSON data from OpenWeatherMap.org's API
url="http://api.openweathermap.org/data/2.5/forecast/city?id=%s&APPID=%s&cnt=%s"%(cityID,appID,days)
response = requests.get(url)
response.raise_for_status() # Load JSON data into a Python variable.
weatherData = json.loads(response.text) # Print weather descriptions.
#主要获取weatherData---weather---main和description信息
w = weatherData['list']
print('Current weather in %s:' % (cityName))
print(w[0]['weather'][0]['main'], '-', w[0]['weather'][0]['description'])
print()
print('Tomorrow:')
print(w[1]['weather'][0]['main'], '-', w[1]['weather'][0]['description'])
print()
print('Day after tomorrow:')
print(w[2]['weather'][0]['main'], '-', w[2]['weather'][0]['description']) '''
len(weatherData)
Out[21]: 5
for i in weatherData:
print(i)
city #城市信息
cod #内部参数
cnt #预测天数
list #信息列表,主要获取weatherData---weather---main和description信息
message #内部参数 ''' '''
weatherData
Out[23]:
{'city': {'coord': {'lat': 30.25, 'lon': 107.75},
'country': 'CN',
'id': 1814905,
'name': 'Chongqing Shi',
'population': 0,
'sys': {'population': 0}},
'cnt': 1,
'cod': '200',
'list': [{'clouds': {'all': 44},
'dt': 1460775600,
'dt_txt': '2016-04-16 03:00:00',
'main': {'grnd_level': 937.55,
'humidity': 98,
'pressure': 937.55,
'sea_level': 1025.81,
'temp': 288.16,
'temp_kf': 0.4,
'temp_max': 288.16,
'temp_min': 287.759},
'rain': {'3h': 0.01},
'sys': {'pod': 'd'},
'weather': [{'description': 'light rain',
'icon': '10d',
'id': 500,
'main': 'Rain'}],
'wind': {'deg': 267.501, 'speed': 1.63}}],
'message': 0.0109} '''
获取天气预报API的更多相关文章
- [整]C#获取天气预报信息(baidu api)包括pm2.5
/// <summary> /// 获取天气预报信息 /// </summary> /// <returns></returns> public Bai ...
- 天气预报API(四):全国城市代码列表(“新编码”)
说明 天气预报API系列文章涉及到的天气网站10个左右,只发现了中国气象频道和腾讯天气城市代码参数特别: 暂且称 中国气象频道.腾讯天气使用的城市代码为 "新编码" 注:中国气象频 ...
- 聚合数据全国天气预报api接口
查询天气预报在APP中常用的一个常用功能,聚合数据全国天气预报api接口可以根据根据城市名/id查询天气.根据IP查询天气.据GPS坐标查询天气.查询城市天气三小时预报,并且支持全国不同城市天气预报查 ...
- 天气预报API简单实现
本人小白,觉得好玩,就注册了一个博客.一时也不知道写些什么,就把昨天做的一个简单的网页天气预报写一下吧,希望对各位看官有所帮助. 运行环境:php+mysql+WIN/Linux,框架什么的都无所谓了 ...
- Android访问中央气象台的天气预报API得到天气数据
最新说明:该接口已失效! 2014-03-04 可申请它公布的API,需申请:http://smart.weather.com.cn/wzfw/smart/weatherapi.shtml 在用A ...
- (41)zabbix监控api接口性能及可用性 天气预报api为例
现在各种应用都走api,例如淘宝,天气预报等手机.pad客户端都是走api的,那么平时也得对这些api做监控了.怎么做呢?zabbix的web监控是不二选择了.今天就以天气预报api作为一个例子. 天 ...
- 如何用全国天气预报API接口进行快速开发
最近公司项目有一个全国天气预报的小需求,想着如果用现成的API就可以大大提高开发效率,在网上的API商店搜索了一番,发现了 APISpace,它里面的全国天气预报API非常符合我的开发需求. 全国 ...
- 天气预报API开发
天气预报API开发 一. 寻觅篇 最近想要跟着视频练习一下利用API开发一个天气预报系统,就在网上找了一下可以用的API,结果好多都已经失效了... 1. 百度车联网天气预报 ...
- Struts2中获取servlet API的几种方式
struts2是一个全新的MVC框架,如今被广大的企业和开发者所使用,它的功能非常强大.这给我们在使用servlet 纯java代码写项目的时候带来了福音.但是一般来说,我们的项目不到一定规模并不需要 ...
随机推荐
- jquery打印页面(jquery.jqprint)
使用jquery进行打印时,所需js包:jquery-1.4.4.min.js.jquery.jqprint-0.3.js 但如果使用高版本的jquery(jquery-1.9.1.min.js)时, ...
- Beta 冲刺 随笔合集
团队展示: Team一二一 Beta 冲刺 凡事预则立 Beta冲刺 一 Beta冲刺 二 Beta冲刺 三 Beta冲刺 四 Beta冲刺 五 Beta冲刺 六 Beta冲刺 七 Beta总结 用户 ...
- IP工具类
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.servlet.http.HttpServletReques ...
- Test Scenarios for Excel Export functionality
1 File should get exported in proper file extension2 File name for the exported excel file should be ...
- Delphi编码规范
以下是在之前的公司与别人共同参与制定的Delphi开发规范(5年前了,那时用的还是Delphi7,部分规则可能有些过时,但不整理了,觉得有用的人,自己整理成适合自己的开发规范吧), 目 录一.序 ...
- python之FTP上传和下载
# FTP操作 import ftplib host = '192.168.20.191' username = 'ftpuser' password = 'ftp123' file = '1.txt ...
- vue实现带规格商品的表格编辑
实现效果: 需求分析: 商品分为 启用规格 和 未启用规格 两种状态, 启用时显示带规格表格, 不启用时显示无规格价格 规格大项最多添加两个, 比如 "颜色", "尺寸& ...
- 一本通1548【例 2】A Simple Problem with Integers
1548:[例 2]A Simple Problem with Integers 题目描述 这是一道模板题. 给定数列 a[1],a[2],…,a[n],你需要依次进行 q 个操作,操作有两类: 1 ...
- 51nod1268(基础dfs)
解题思路:直接搜索找就行了,搜两边,一个是加入这个数字,一边是不加入这个数字 代码: #include<iostream>#include<algorithm>#define ...
- So you want to be a 2n-aire? UVA - 10900(概率)
题意: 初始值为1, 每次回答一个问题,如果答对初始值乘2,答错归0,结束,一共有n个问题,求在最优的策略下,最后值的期望值 解析: 注意题中的一句话 每个问题的答对概率在t和1之间均匀分布 也就 ...
