gpt4 book ai didi

python - 如何通过weather api获取降水量/降雨量?

转载 作者:太空宇宙 更新时间:2023-11-04 03:43:43 25 4
gpt4 key购买 nike

我累了Open Weather Map因为文档说它有“雨”,但当我称它为“雨”时却没有。所以我尝试了 Python Weather API但是来自 weather.com、noaa 或 yahoo weather 的这些选项都没有降雨或降水。所以我尝试了 Wunderground但这似乎只适用于美国城市,除此之外,我懒得去买 key 。

有人知道从这里去哪里吗?

在打开的天气图上显示有雨,但我在结果中没有得到:

JSON 调用示例

{"coord":{"lon":139,"lat":35},
"sys":{"country":"JP","sunrise":1369769524,"sunset":1369821049},
"weather":[{"id":804,"main":"clouds","description":"overcast clouds","icon":"04n"}],
"main":{"temp":289.5,"humidity":89,"pressure":1013,"temp_min":287.04,"temp_max":292.04},
"wind":{"speed":7.31,"deg":187.002},
"rain":{"3h":0}, # on this line
"clouds":{"all":92},
"dt":1369824698,
"id":1851632,
"name":"Shuzenji",
"cod":200}

但是,当我这样调用它的时候

from pprint import pprint
import requests
r = requests.get('http://api.openweathermap.org/data/2.5/weather?q=Vancouver')
pprint(r.json())

我得到了没有降雨/降水的东西。

{u'base': u'cmc stations',
u'clouds': {u'all': 0},
u'cod': 200,
u'coord': {u'lat': 49.25, u'lon': -123.12},
u'dt': 1406042326,
u'id': 6173331,
u'main': {u'humidity': 77,
u'pressure': 862,
u'temp': 289.33,
u'temp_max': 290.93,
u'temp_min': 288.15},
u'name': u'Vancouver',
u'sys': {u'country': u'CA',
u'message': 0.1867,
u'sunrise': 1406032353,
u'sunset': 1406088323},
u'weather': [{u'description': u'Sky is Clear',
u'icon': u'01d',
u'id': 800,
u'main': u'Clear'}],
u'wind': {u'deg': 104.001, u'speed': 2.75}}

最佳答案

根据documentation , weather, rain.3h, snow.3h 都是optional参数,提示不会一直包含在结果中。

我认为这意味着如果在相关时间没有下雨或下雪,则不会报告下雨和下雪 - 例如在您的示例中它说“天空晴朗” - 但也有可能这意味着他们只是不保证雨/雪数据。

关于python - 如何通过weather api获取降水量/降雨量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24892850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com