失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 获取天气预报API

获取天气预报API

时间:2020-07-17 16:34:48

相关推荐

获取天气预报API

sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频)

/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 @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"#我的免费appIDappID="0383ae59663e14ab5a6855d5b6ad5d00"#获取天气天数days="3"# Download the JSON data from 's APIurl="/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]: 5for i in weatherData:print(i)city #城市信息cod #内部参数cnt #预测天数list #信息列表,主要获取weatherData---weather---main和description信息message #内部参数''''''weatherDataOut[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': '-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}'''

python风控评分卡建模和风控常识

/course/introduction.htm?courseId=1005214003&utm_campaign=commission&utm_source=cp-400000000398149&utm_medium=share

如果觉得《获取天气预报API》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。