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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
javaspringbootmockito@injectmock说明如何仅模拟选定的依赖项   尝试在eclipse项目中加载dll时发生java UnsatifiedLinkError   java在文本文件上多次匹配模式?   java如何使用JSON显示天气数据?   java导出内部对象   java获取以链表中特定字符开头的所有元素   swing使主方法等待较小的方法(java)   java如何制作对象的深度副本?   java访问SpringMVC项目中的外部ELEAF文件   java打印没有元素邻接的所有子序列数组   java为什么findLoadedClass方法调用返回不同的结果   java如何在安卓中从sqlite数据库获取单个数据?   java我正在编写一个程序,为twitch流媒体应用程序的eq生成随机竞赛/类   java如何绕过SSL握手javax。网ssl。SSLHandshakeException   java关于LibGdx addListener   线程中的java安卓socket连接