Python库与ClimaCell Weather API接口

climacell-python的Python项目详细描述


顶极Python

Climacell Weather API的python接口

安装

使用pip,从PyPi安装 Python包管理器。在

pip install climacell-python

此库支持以下Python实现:

  • Python 3.5
  • Python 3.6
  • Python 3.7
  • Python 3.8

入门

开始使用ClimaCell API很容易。创建 ClimacellApiClient你准备好开始提出请求了。在

API认证

ClimacellApiClient需要您在仪表板中找到的Climacell键。将其直接传递给构造函数

^{pr2}$

ClimaCell文档

查看ClimaCell docs以获取有关其天气API的详细信息。在

fields参数对于选择要检索的数据非常重要。可以找到所有可能字段的列表以及哪个端点接受它们here。在

提出请求

客户端将返回一个ClimacellResponse对象,它是requests'响应对象的包装器。在

您可以调用所有普通请求的响应方法以及一个data()方法,该方法包含所有特定于ClimaCell的数据。在

数据的measurements属性是一个字典,它使用字段字符串作为键提供字段结果。可以找到每个端点接受的所有字段的列表here。在

下面是这个库支持的所有端点的示例。在

实时

返回的数据是针对特定位置的单个最新观察结果。在

>>>fromclimacell_apiimportClimacellApiClient>>>client=ClimacellApiClient(YOUR_KEY)>>>r=client.realtime(lat=40,lon=50,fields=['temp','wind_gust'])>>>r.status_code200>>>r.json()# for raw json{'lat':40,'lon':50,...}>>>data=r.data()>>>data.lat40>>>data.lon50>>>data.observation_timedatetime.datetime(2020,6,26,13,45,26,tzinfo=tzutc())>>>measurements=data.measurements>>>measurements['temp'].value43>>>measurements['temp'].units'C'>>>measurements['wind_gust'].value7.5>>>measurements['wind_gust'].units'm/s'

Nowcast

返回的数据是特定位置的预测数据列表。在

>>>fromclimacell_apiimportClimacellApiClient>>>client=ClimacellApiClient(YOUR_KEY)>>>r=client.nowcast(lat=40,lon=50,timestep=30,start_time='now',end_time='2020-06-22T20:47:00Z'fields=['temp','wind_gust'])>>>r.status_code200>>>r.json()# for raw json[{'lat':40,'lon':50,...},{'lat':40,'lon':50,...},...]>>>data=r.data()>>>data[0].lat40>>>data[0].lon50>>>data[0].observation_timedatetime.datetime(2020,6,26,13,45,26,tzinfo=tzutc())>>>measurements=data[0].measurements>>>measurements['temp'].value43>>>measurements['temp'].units'C'>>>measurements['wind_gust'].value7.5>>>measurements['wind_gust'].units'm/s'

小时预测

返回的数据是未来96小时内特定位置的预测数据列表。在

>>>fromclimacell_apiimportClimacellApiClient>>>client=ClimacellApiClient(YOUR_KEY)>>>r=client.forecast_hourly(lat=40,lon=50,start_time='now',end_time='2020-06-22T20:47:00Z'fields=['temp','wind_gust'])>>>r.status_code200>>>r.json()# for raw json[{'lat':40,'lon':50,...},{'lat':40,'lon':50,...},...]>>>data=r.data()>>>data[0].lat40>>>data[0].lon50>>>data[0].observation_timedatetime.datetime(2020,6,26,13,45,26,tzinfo=tzutc())>>>measurements=data[0].measurements>>>measurements['temp'].value43>>>measurements['temp'].units'C'>>>measurements['wind_gust'].value7.5>>>measurements['wind_gust'].units'm/s'

每日预测

返回的数据是未来15天内特定位置的每日预测数据列表。每日预测数据有许多字段的最大和最小数据。例如,temp max表示一天的高温,temp min表示一天的低温。其中包括最小和最大数据点的预测观测时间。在

>>>fromclimacell_apiimportClimacellApiClient>>>client=ClimacellApiClient(YOUR_KEY)>>>r=client.forecast_daily(lat=40,lon=50,start_time='now',end_time='2020-06-22T20:47:00Z'fields=['temp'])>>>r.status_code200>>>r.json()# for raw json[{'lat':40,'lon':50,...},{'lat':40,'lon':50,...},...]>>>data=r.data()>>>data[0].lat40>>>data[0].lon50>>>data[0].observation_timedatetime.datetime(2020,6,26)>>>measurements=data[0].measurements>>>measurements['temp']['max'].value43>>>measurements['temp']['max'].units'C'>>>measurements['temp']['max'].observation_timedatetime.datetime(2020,6,26,13,45,26,tzinfo=tzutc())>>>measurements=data[0].measurements>>>measurements['temp']['min'].value31>>>measurements['temp']['min'].units'C'>>>measurements['temp']['min'].observation_timedatetime.datetime(2020,6,26,23,45,26,tzinfo=tzutc())

历史顶极细胞

返回的数据是过去6小时内特定位置的预测数据列表。在

>>>fromclimacell_apiimportClimacellApiClient>>>client=ClimacellApiClient(YOUR_KEY)>>>r=client.historical_climacell(lat=40,lon=50,timestep=30,start_time='2020-06-22T20:47:00Z',end_time='now'fields=['temp','wind_gust'])>>>r.status_code200>>>r.json()# for raw json[{'lat':40,'lon':50,...},{'lat':40,'lon':50,...},...]>>>data=r.data()>>>data[0].lat40>>>data[0].lon50>>>data[0].observation_timedatetime.datetime(2020,6,26,13,45,26,tzinfo=tzutc())>>>measurements=data[0].measurements>>>measurements['temp'].value43>>>measurements['temp'].units'C'>>>measurements['wind_gust'].value7.5>>>measurements['wind_gust'].units'm/s'

历史站

返回的数据是过去4周内特定地点的预测数据列表。这是气象站的数据,而不是气候室的具体读数

>>>fromclimacell_apiimportClimacellApiClient>>>client=ClimacellApiClient(YOUR_KEY)>>>r=client.historical_station(lat=40,lon=50,start_time='2020-06-22T20:47:00Z',end_time='now'fields=['temp','wind_gust'])>>>r.status_code200>>>r.json()# for raw json[{'lat':40,'lon':50,...},{'lat':40,'lon':50,...},...]>>>data=r.data()>>>data[0].lat40>>>data[0].lon50>>>data[0].observation_timedatetime.datetime(2020,6,26,13,45,26,tzinfo=tzutc())>>>measurements=data[0].measurements>>>measurements['temp'].value43>>>measurements['temp'].units'C'>>>measurements['wind_gust'].value7.5>>>measurements['wind_gust'].units'm/s'

洞察火指数

返回的数据是基于该位置20年平均值的单一火灾指数

>>>fromclimacell_apiimportClimacellApiClient>>>client=ClimacellApiClient(YOUR_KEY)>>>r=client.insights_fire_index(lat=40,lon=50)>>>r.status_code200>>>r.json()# for raw json[{'fire_index':22.123}]>>>data=r.data()>>>data.fire_index22.123

错误

通过从data()方法返回代码和消息来处理错误消息

>>>fromclimacell_apiimportClimacellApiClient>>>client=ClimacellApiClient(YOUR_KEY)>>>r=client.realtime(lat=40,lon=9999,fields=['temp'])>>>r.status_code400>>>r.json()# for raw json{'statusCode':400,'errorCode':'BadRequest','message':'lon must be in the range -180..180'}>>>data=r.data()>>>data.error_code'BadRequest'>>>data.error_message'lon must be in the range -180..180'

单位

除fire_index外,每个端点都采用一个可选的units参数。在

units='si'# Default value and returns the scientific unit of measurement for the fieldunits='us'# Returns the US unit of measurement for the field.

贡献

提交拉取请求

  1. Fork这个official repository。在
  2. Create a topic branch.
  3. 实现您的特性或错误修复。在
  4. 添加、提交和推送您的更改。在
  5. Submit a pull request.

运行测试套件

$ pip install -e .[dev]$ pytest

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

推荐PyPI第三方库


热门话题
java Spring注入SessionFactory或EntityManagerFactory而不是EntityManager   JavaApacheSolr,需要单个字段的多个字段,同时优化查询以仅命中特定索引   java未处理的内部错误。组织。阿帕奇。hadoop。映射。作业控制。作业控制。addJob   java通过post请求向进程传递动态文件名   Java在几秒钟内处理位图上的每个像素   java Payara服务器和NetBeans 8.2:请求在不支持异步操作的筛选器或servlet的范围内   java JTable:复杂单元渲染器   hashmap Java按值传递和按引用传递   用于列<V,T>的java JavaFX列排序,其中T扩展了ObservableList<U>   java如何将安卓 progressbar(水平)的颜色更改为不同的部分?   java如何将不同模块的类绑定到jar?   java如何将图像上传/下载到GAE数据存储?   Java中的eclipse三值运算符帮助   http在哪些方法调用java之后向服务器发送真正的请求?