wunderground_historical.py

https://gist.github.com/philshem/8864437
Wunderground API: Streamlined python 2.7 code using the requests package. Must register at  http://www.wunderground.com/weather/api/ and insert your personal key.
 import requests
 data = requests.get('http://api.wunderground.com/api/INSERT_KEY_HERE/geolookup/conditions/q/Switzerland/Zurich.json').json()
 location = data['location']['city']
 temp_c = data['current_observation']['temp_c']
 print "Current temperature in %s is: %s C" % (location, temp_c)
 import requests
 def get_precip(gooddate):
 urlstart = 'http://api.wunderground.com/api/INSERT_KEY_HERE/history_'
 urlend = '/q/Switzerland/Zurich.json'
  
 url = urlstart + str(gooddate) + urlend
 data = requests.get(url).json()
 for summary in data['history']['dailysummary']:
 print ','.join((gooddate,summary['date']['year'],summary['date']['mon'],summary['date']['mday'],summary['precipm'], summary['maxtempm'], summary['meantempm'],summary['mintempm']))
  
 if __name__ == "__main__":
 from datetime import date
 from dateutil.rrule import rrule, DAILY
  
 a = date(2013, 1, 1)
 b = date(2013, 12, 31)
  
 for dt in rrule(DAILY, dtstart=a, until=b):
 get_precip(dt.strftime("%Y%m%d"))

转载于:https://www.cnblogs.com/gisalameda/p/7400648.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值