一个最小的预报,我的客户。
requests-forecast的Python项目详细描述
有关完整的文档和api选项,请参见:https://developer.forecast.io/docs/v2
要求
- Python2.5+
- 请求1.2.0+
安装
要安装请求预测,只需:
$ pip install requests-forecast
快速启动
创建客户机
>>> from requests_forecast import Forecast >>> forecast = Forecast(apikey='FORECAST_API_KEY', latitude=38.9717, longitude=-95.235)
获取当前条件
>>> current = forecast.get_currently() >>> print current['temperature'] 58.9
获取分钟条件
>>> current = forecast.get_minutely() >>> current['summary'] u'Mostly cloudy for the hour.' >>> current['data'][0].keys() [u'precipIntensity', u'time']
获取小时条件
>>> current = forecast.get_hourly() >>> current['temperature'] 59.52 >>> forecast.get_hourly()['summary'] Mostly cloudy until tomorrow afternoon. >>> forecast.get_hourly()['data'][0]['temperature'] >>> 59.52
获得日常条件
>>> forecast.get_daily()['summary'] u'Mixed precipitation off-and-on throughout the week; temperatures peaking at 70\xb0 on Sunday.' >>> forecast.get_daily()['data'][0]['temperatureMax'] 63.85 >>> forecast.get_daily()['data'][0]['temperatureMin'] 35.05
获取警报
>>> forecast.alerts() { "expires": 1366898400, "uri": "http://alerts.weather.gov/cap/wwacapget.php?x=KS124EFAC89CD0.FreezeWarning.124EFAD6F320KS.TOPNPWTOP.8ab7d76a4db42b9136a1a6849a631097", "title": "Freeze Warning for Douglas, KS" }
示例用法
from datetime import datetime from requests_forecast import Forecast forecast = Forecast(apikey='YOUR-API-KEY') data = forecast.get(latitude=38.9717, longitude=-95.235) >>> forecast.get_currently()['temperature'] 58.9 data = forecast.get(latitude=38.9717, longitude=-95.235, time=datetime(year=2013, month=12, day=29)) >>> forecast.get_currently()['temperature'] 58.9 >>> forecast.get_currently()['temperature'] 36.75
许可证
新BSD