无痛苦地访问netatmo天气api

patatmo的Python项目详细描述


BuildDocumentationCoveragePyPi

这个包提供了对Netatmo的简单访问 API。它是无痛的因为它完全 智能地向您隐藏OAuth2身份验证。

免责声明

This software to access theNetatmo Weather APIemerged as part of thesis and also out of private interest. The author is not in any way affiliated with Netatmo (SAS).

能力

目前,天气api的方法GetpublicdataGetstationsdataGetmeasure已实现。

示例用法

获取区域内所有公共站点数据的示例 汉堡/德国:

从命令行

聪明的方法是设置配置文件~/.patatmo/settings.conf

[account]
username=user.email@internet.com
password=5uP3rP45sW0rD
client_id=03012823b3fd2e420fbf980b
client_secret=YXNkZmFzZGYgamFzamYgbGFzIG

然后在命令行上:

netatmo-getpublicdata \
    --lat_ne 53.7499 \
    --lat_sw 53.3809 \
    --lon_ne 10.3471 \
    --lon_sw 9.7085

作为一行:

netatmo-getpublicdata \
    --user "user.email@internet.com"\
    --password "5uP3rP45sW0rD"\
    --id "5uP3rP45sW0rD"\
    --secret "YXNkZmFzZGYgamFzamYgbGFzIG"\
    --lat_ne 53.7499 \
    --lat_sw 53.3809 \
    --lon_ne 10.3471 \
    --lon_sw 9.7085

使用环境变量(也可以在其他地方设置, 例如,在您的.bashrc)中:

exportNETATMO_USERNAME="user.email@internet.com"exportNETATMO_PASSWORD="5uP3rP45sW0rD"exportNETATMO_CLIENT_ID="03012823b3fd2e420fbf980b"exportNETATMO_CLIENT_SECRET="YXNkZmFzZGYgamFzamYgbGFzIG"
netatmo-getpublicdata \
    --lat_ne 53.7499 \
    --lat_sw 53.3809 \
    --lon_ne 10.3471 \
    --lon_sw 9.7085

来自python

获取区域内所有公共站点数据的示例 汉堡/德国:

importpatatmo# your netatmo connect developer credentialscredentials={"password":"5uP3rP45sW0rD","username":"user.email@internet.com","client_id":"03012823b3fd2e420fbf980b","client_secret":"YXNkZmFzZGYgamFzamYgbGFzIG"}# configure the authenticationauthentication=patatmo.api.authentication.Authentication(credentials=credentials,tmpfile="temp_auth.json")# providing a path to a tmpfile is optionally.# If you do so, the tokens are stored there for later reuse,# e.g. next time you invoke this script.# This saves time because no new tokens have to be requested.# New tokens are then only requested if the old ones expire.# create a api clientclient=patatmo.api.client.NetatmoClient(authentication)# lat/lon outline of Hamburg/Germanyhamburg_region={"lat_ne":53.7499,"lat_sw":53.3809,"lon_ne":10.3471,"lon_sw":9.7085,}# issue the API requesthamburg=client.Getpublicdata(region=hamburg_region)# convert the response to a pandas.DataFrameprint(hamburg.dataframe.to_csv())
,index,altitude,humidity,id,latitude,longitude,pressure,temperature,time_humidity,time_pressure,time_temperature,timezone
0,0,30.0,67.0,70:ee:50:12:9a:b8,53.51695,10.15599,1015.4,22.5,2017-08-26 16:36:19,2017-08-26 16:36:36,2017-08-26 16:36:19,Europe/Berlin
1,1,23.0,65.0,70:ee:50:03:da:4c,53.523361337741,10.16719281615,1013.2,22.8,2017-08-26 16:35:33,2017-08-26 16:36:11,2017-08-26 16:35:33,Europe/Berlin
2,2,25.0,80.0,70:ee:50:02:95:92,53.517903,10.165769,1016.9,21.5,2017-08-26 16:38:17,2017-08-26 16:38:23,2017-08-26 16:38:17,Europe/Berlin
3,3,,,70:ee:50:17:bd:96,53.530789,10.127101,1010.1,,,2017-08-26 16:35:01,,Europe/Berlin
4,4,15.0,83.0,70:ee:50:03:bc:2c,53.530948,10.134062,1013.5,20.6,2017-08-26 16:35:07,2017-08-26 16:35:25,2017-08-26 16:35:07,Europe/Berlin
5,5,29.0,72.0,70:ee:50:03:72:28,53.545417580965,10.160120337925,1013.7,22.5,2017-08-26 16:42:05,2017-08-26 16:42:40,2017-08-26 16:42:05,Europe/Berlin
6,6,24.0,70.0,70:ee:50:14:42:1c,53.5698669,10.1554532,1011.4,23.2,2017-08-26 16:33:11,2017-08-26 16:33:55,2017-08-26 16:33:11,Europe/Berlin
7,7,31.0,69.0,70:ee:50:06:92:40,53.57426932987,10.161323698426,1013.7,22.3,2017-08-26 16:35:02,2017-08-26 16:35:30,2017-08-26 16:35:02,Europe/Berlin
8,8,26.0,68.0,70:ee:50:01:3c:f6,53.5811,10.1485,1016.2,23.2,2017-08-26 16:40:57,2017-08-26 16:41:21,2017-08-26 16:40:57,Europe/Berlin

安装

这个包裹在PyPi上。要安装patatmo, 运行

pip install --user patatmo

文档

你可以找到这个包的详细文档 here on on Gitlab

开发

以下内容可能只对开发人员感兴趣

本地安装

通过pip

# local user library under ~/.local
pip3 install --user .
# in "editable" mode
pip3 install --user -e .

测试

要运行all测试,需要指定有效的credentials和 测试站的设备和型号ID。你也可以在文件里这样做 tests/USER_DATA.json(例如,复制示例文件cp tests/USER_DATA.json.example tests/USER_DATA.json并对其进行调整)或通过 环境变量

NETATMO_CLIENT_ID
NETATMO_CLIENT_SECRET
NETATMO_USERNAME
NETATMO_PASSWORD
NETATMO_DEVICE_ID
NETATMO_MODULE_ID

否则,只运行可能的测试。

然后:

  • make test直接运行所有测试
  • make testverbose使用详细输出直接运行所有测试
  • make setup-test通过./setup.py test机制运行所有测试
  • make coverage获取测试覆盖率

版本控制

  • make increase-patch以增加修补程序版本号
  • make increase-minor增加次要版本号
  • make increase-major增加主版本号

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

推荐PyPI第三方库


热门话题
java Glassfish3+Webstart+JNLP不会启动   支持单元格选择的java行   java FTP组织。阿帕奇。平民网格式错误的ServerReplyException:截断的服务器回复:“220”   java为什么公用文件夹下的更改会触发自动重新加载?   使用Java graphics相对于线条摆动打印线条标签   java从代码中的任何位置访问HttpContext、HttpServletRequest和HttpServletResponse   java如何跳过JSON中的第一个元素   Java 安卓列表字符串带有数字和国家/地区字母的排序字符串   从文件创建响应elasticsearch响应时发生java错误   java哈希表与关键词的获取   amazon web服务如何获取特定的lambda度量统计信息,比如使用java的iteratorAge   从异步任务返回对象时出现java问题   java bufferedReader。readLine()无法读取整个文件行   如何在JavaSpring引导应用程序中跟踪用户的登录   java为什么从基类继承的子类方法不能打印自身字段的值?