pyqweather
和风天气 api for python3。
安装
使用pip
pip install pyqweather
前置条件
通过和风天气官网获取开发Key 如何获取你的Key
快速使用
调用“城市搜索”接口
# coding:utf-8
from pyqweather import QWeatherConfig
from pyqweather.auth import SimpleAuthCredential
from pyqweather.factories import QWeatherFactory
endpoint = 'https://geoapi.qweather.com/v2'
auth_credential = SimpleAuthCredential('key')
conf = QWeatherConfig(endpoint, auth_credential)
pack = QWeatherFactory().create_geo_pack(conf)
resp = pack.city_lookup('北京')
if resp.get_code() == '200':
print('OK')
else:
print('Error')
使用App Key设置环境变量
Mac OS X/Linux/Unix
export QWEATHER_SDK_APP_KEY=<Your App Key>
export QWEATHER_SDK_PUBLIC_ID=<Your PublicId>
Windows
set QWEATHER_SDK_APP_KEY=<Your App Key>
set QWEATHER_SDK_PUBLIC_ID=<Your PublicId>
通过环境变量进行接口调用
# coding:utf-8
from pyqweather import QWeatherConfig
from pyqweather.auth import EnvironmentVariableSignAuthCredential
from pyqweather.factories import QWeatherFactory
endpoint = 'https://geoapi.qweather.com/v2'
conf = QWeatherConfig(endpoint, EnvironmentVariableSignAuthCredential()) # 使用数字签名的方式
factory = QWeatherFactory()
pack = factory.create_geo_pack(conf)
resp = pack.city_lookup('北京')
print(resp)
特殊的地方
目前仅支持以简单KEY认证的方式调用空气质量(Beta)接口, 使用数字签名会报错。
使用简单KEY认证的方式示例:
conf = QWeatherConfig(self._domain,EnvironmentVariableSimpleAuthCredential())
factory = QWeatherFactory()
pack = factory.create_airquality_pack(conf)
resp = pack.airquality_now('101090101')
print(resp.aqi)
接口的映射
对应官网的接口列表,组件也定义了相应的Package类, 你总是可以通过工厂方法 QWeatherFactory().create_xxx()的方式创建对应的API类(xxx表示下表的Package)。
具体对应关系如下表所示:
| 接口分组 | Package |
|---|---|
| GeoAPI | geo_pack |
| 城市天气 | weather_pack |
| 分钟预报 | minutely_pack |
| 格点天气 | grid_weather_pack |
| 预警 | weather_warning_pack |
| 天气指数 | indices_pack |
| 空气质量(beta) | air_quality_pack |
| 空气质量 | air_pack |
| 时光机 | time_machine_pack |
| 热带气旋(台风) | tropical_cyclone_pack |
| 海洋数据 | ocean_pack |
| 太阳辐射 | solar_radiation_pack |
| 天文 | astronomy_pack |
更多内容
官方文档
Metadata
Release files for pyqweather 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyqweather-1.0.6.tar.gz | 25.6 kB | Without provenance | Details for pyqweather-1.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyqweather-1.0.6-py3-none-any.whl | Python 3 | none | any | Details for pyqweather-1.0.6-py3-none-any.whl |
Total release size: 68.7 kB
Release files / pyqweather-1.0.6.tar.gz
| Download URL | pyqweather-1.0.6.tar.gz |
|---|---|
| Size | 25.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8bfe555f2f8fe5efb0892fce2d556cba0ae51ff2af1537340fcbff571d8aee39
|
|
BLAKE2b-256 checksum How to use checksums |
fca1c82572c3d5840477f99c2ee135084e3fcd5abbc6df757f711ee5df5c1870
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Release files / pyqweather-1.0.6-py3-none-any.whl
| Download URL | pyqweather-1.0.6-py3-none-any.whl |
|---|---|
| Size | 43.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
63b26cd2cf7ca39128b120f942748b27f9dcfe69a99e7b344c1f7aa2103f3899
|
|
BLAKE2b-256 checksum How to use checksums |
6de18468c3b09a6af9f6f98ac9663019277123a2b91484d7e496340a526d8bff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Security for pyqweather 1.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.