2014-07-22 273 views
2

我累Open Weather Map因爲文檔說它有「雨」,但是當我稱它不是。所以我嘗試Python Weather API,但weather.com,noaa或yahoo天氣的這些選項都沒有降雨或降水。所以我嘗試Wunderground,但這似乎只適用於美國的城市,最重要的是,我不能爲購買鑰匙而煩惱。如何通過天氣api獲取降水量/降雨量?

任何人都知道該從哪裏出發?

在開放的氣象圖,它說有雨,但我不明白的是,在結果:

例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}} 

回答

2

按照documentationweatherrain.3hsnow.3h都是optional參數,這表明他們不會永遠被列入結果。

我解釋這意味着雨,如果沒有雨或雪在有問題的時候雪將不報告 - 比如在你的例子在那裏說:「天空是明確的」 - 但它也這可能意味着他們只是不能保證雨/雪數據。

+0

我不知道。我在那裏開始下雨,所以我測試了它,但仍然沒有下雨的關鍵。 –

+0

通常雨田會隨着時間的幾個小時內累計降雨值後進行報告。在OpenWeatherMap中,這是3個小時。 – Amitabh