Python 如何通过天气api获取降水量/降雨量?

Python 如何通过天气api获取降水量/降雨量?,python,python-requests,weather,weather-api,Python,Python Requests,Weather,Weather Api,我累了,因为医生说有“雨”,但当我叫它时,它没有。所以我试过了,但从weather.com、noaa或yahoo weather这些选项都没有降雨或降水。所以我试过了,但这似乎只适用于美国的城市,而且最重要的是,我不想费心买钥匙 有人知道从这里去哪里吗 在开放式天气图上显示有雨,但我从结果中看不到: JSON调用示例 {"coord":{"lon":139,"lat":35}, "sys":{"country":"JP","sunrise":1369769524,"sunset":1369821

我累了,因为医生说有“雨”,但当我叫它时,它没有。所以我试过了,但从weather.com、noaa或yahoo weather这些选项都没有降雨或降水。所以我试过了,但这似乎只适用于美国的城市,而且最重要的是,我不想费心买钥匙

有人知道从这里去哪里吗

在开放式天气图上显示有雨,但我从结果中看不到:

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}}
根据
天气
雨.3h
雪.3h
都是
可选的
参数,表明它们并不总是包含在结果中

我的解释是,如果当时没有雨或雪,就不会报告雨和雪——比如在你的例子中,它说“天空晴朗”——但也有可能这意味着它们不能保证雨/雪数据。

我发现了雨;)这并不容易,但成功了。它存在

    fetch(https://api.openweathermap.org/data/2.5/weather?q=${city}&units=metric&appid=${apiKey})
  .then(res => res.json())
  .then(data => {
    console.log(data);
    const { pressure, temp, humidity } = data.main;
    const { speed, deg } = data.wind;
    const { description } = data.weather[0];
    const rain = data.rain['1h'];
    console.log(rain)
  });

我不确定。我所在的地方开始下起了疯狂的雨,所以我测试了一下,但仍然没有降雨的关键。通常在累积了几个小时的降雨值后,会报告降雨场。在OpenWeatherMap中,这是3个小时。这真的很奇怪,他们的水瓶不能支持基本的测量和服务器——推测的结果吗?每隔几分钟实时报告一次(价值,推测性:bool)将允许更多。。。但是,呃,这不是UX讨论。