openweathermap.org API包装器
openweather的Python项目详细描述
一个基本的openweathermap.org API客户端。
关于实验缓存的新闻:
存储库中的版本当前领先于最新版本 在pypy上发布的版本(0.9)。它的特点是缓存。
如果缓存未显式停用,则函数 “get_historic_weather()”将从api获取的数据存储在sqlite中 数据库在随后的请求中,直接从 数据库(如果可用)。
要停用缓存,请使用
ow=openweather.OpenWeather(cache=False)
为了显式地设置缓存数据库文件的路径,请使用
ow=openweather.OpenWeather(cache="path/to/cache.db")
安装
要安装最新版本:
pip install openweather
对于存储库中的最新版本,请使用:
pip install git+https://github.com/marians/openweather.git
python模块示例
importopenweatherfromdatetimeimportdatetime# create clientow=openweather.OpenWeather()# find weather stations near mestations=ow.find_stations_near(7.0,# longitude50.0,# latitude100# kilometer radius)# iterate resultsforstationinstations:printstation# get current weather at Cologne/Bonn airport# (station id = 4885)printow.get_weather(4885)# historic weatherstart_date=datetime(2013,09,10)end_date=datetime(2013,09,15)# default: hourly intervalprintow.get_historic_weather(4885,start_date,end_date)# daily aggregatesprintow.get_historic_weather(4885,start_date,end_date,"day")
命令行客户端示例
打印站点ID 4885的当前天气:
$ openweather -s 4885
打印2013-10-01年历史天气,车站编号4885:
$ openweather -s 4885 -d 20131001
有关-d或--date参数的有效格式,请参见 daterangestr。
以csv格式打印历史数据
$ python openweather.py -s 4885 -d 20131022 --csv
如果要将数据存储到文件中,这一功能尤其有用…
$ openweather -s 4885 -d 20131022 --csv > weather.csv
…或者想要操作和显示它(使用 csvkit):
$ openweather -s 4885 -d 20131027 --csv|csvcut -c 9,26,30,35,43|csvlook |-------------+-------------+------------+------------+---------------|| dt | main_temp_v | pressure_v | wind_deg_v | wind_speed_v ||-------------+-------------+------------+------------+---------------||1382824800|287.15 |1005||4.1 ||1382835600|290.4 |1008.25 |170|5.93 ||1382839200|289.15 |1007.5 |175|5.1 | ... |1382904000|287.15 |1007|210|5.9 ||1382907600|287.15 |1007|200|6.2 ||1382911200|287.15 |1006|177|5.1 ||||||||-------------+-------------+------------+------------+---------------|
像OpenWeather?
请随意tip me!