# pyqweather
和风天气 api for python3。
[](https://pypi.org/project/pyqweather/)
## 安装
使用pip
```console
pip install pyqweather
```
## 前置条件
通过和风天气官网获取开发Key [如何获取你的Key](https://dev.qweather.com/docs/configuration/project-and-key/)
## 快速使用
调用“城市搜索”接口
```python
# 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
```bash
export QWEATHER_SDK_APP_KEY=<Your App Key>
export QWEATHER_SDK_PUBLIC_ID=<Your PublicId>
```
#### Windows
```shell
set QWEATHER_SDK_APP_KEY=<Your App Key>
set QWEATHER_SDK_PUBLIC_ID=<Your PublicId>
```
#### 通过环境变量进行接口调用
```python
# 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)
```
### <span style="color:#F44336">特殊的地方</span>
目前仅支持以**简单KEY认证的方式**调用空气质量(Beta)接口, 使用数字签名会报错。
使用简单KEY认证的方式示例:
```python
conf = QWeatherConfig(self._domain,EnvironmentVariableSimpleAuthCredential())
factory = QWeatherFactory()
pack = factory.create_airquality_pack(conf)
resp = pack.airquality_now('101090101')
print(resp.aqi)
```
## 接口的映射
对应官网的[接口列表](https://dev.qweather.com/docs/api/),组件也定义了相应的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 |
## 更多内容
### [官方文档](https://dev.qweather.com/docs/start/)
Raw data
{
"_id": null,
"home_page": "https://github.com/imaxu/py-qweather",
"name": "pyqweather",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "xuwh",
"author_email": "xuwhdev@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/fc/a1/c82572c3d5840477f99c2ee135084e3fcd5abbc6df757f711ee5df5c1870/pyqweather-1.0.6.tar.gz",
"platform": null,
"description": "# pyqweather\n\u548c\u98ce\u5929\u6c14 api for python3\u3002\n\n[](https://pypi.org/project/pyqweather/)\n\n## \u5b89\u88c5\n\n\u4f7f\u7528pip\n\n```console\npip install pyqweather\n```\n\n\n\n## \u524d\u7f6e\u6761\u4ef6\n\u901a\u8fc7\u548c\u98ce\u5929\u6c14\u5b98\u7f51\u83b7\u53d6\u5f00\u53d1Key [\u5982\u4f55\u83b7\u53d6\u4f60\u7684Key](https://dev.qweather.com/docs/configuration/project-and-key/)\n\n\n## \u5feb\u901f\u4f7f\u7528\n\u8c03\u7528\u201c\u57ce\u5e02\u641c\u7d22\u201d\u63a5\u53e3\n\n```python\n# coding:utf-8\nfrom pyqweather import QWeatherConfig\nfrom pyqweather.auth import SimpleAuthCredential\nfrom pyqweather.factories import QWeatherFactory\n\nendpoint = 'https://geoapi.qweather.com/v2'\nauth_credential = SimpleAuthCredential('key')\nconf = QWeatherConfig(endpoint, auth_credential)\npack = QWeatherFactory().create_geo_pack(conf)\nresp = pack.city_lookup('\u5317\u4eac')\n\nif resp.get_code() == '200':\n print('OK')\nelse:\n print('Error')\n```\n\n\n### \u4f7f\u7528App Key\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\n\n#### Mac OS X/Linux/Unix\n\n```bash\nexport QWEATHER_SDK_APP_KEY=<Your App Key>\nexport QWEATHER_SDK_PUBLIC_ID=<Your PublicId>\n```\n\n#### Windows\n\n```shell\nset QWEATHER_SDK_APP_KEY=<Your App Key>\nset QWEATHER_SDK_PUBLIC_ID=<Your PublicId>\n```\n\n#### \u901a\u8fc7\u73af\u5883\u53d8\u91cf\u8fdb\u884c\u63a5\u53e3\u8c03\u7528\n\n```python\n# coding:utf-8\nfrom pyqweather import QWeatherConfig\nfrom pyqweather.auth import EnvironmentVariableSignAuthCredential\nfrom pyqweather.factories import QWeatherFactory\n\nendpoint = 'https://geoapi.qweather.com/v2'\nconf = QWeatherConfig(endpoint, EnvironmentVariableSignAuthCredential()) # \u4f7f\u7528\u6570\u5b57\u7b7e\u540d\u7684\u65b9\u5f0f\nfactory = QWeatherFactory()\n\npack = factory.create_geo_pack(conf)\nresp = pack.city_lookup('\u5317\u4eac')\n\nprint(resp)\n```\n\n### <span style=\"color:#F44336\">\u7279\u6b8a\u7684\u5730\u65b9</span>\n\n\u76ee\u524d\u4ec5\u652f\u6301\u4ee5**\u7b80\u5355KEY\u8ba4\u8bc1\u7684\u65b9\u5f0f**\u8c03\u7528\u7a7a\u6c14\u8d28\u91cf\uff08Beta\uff09\u63a5\u53e3\uff0c \u4f7f\u7528\u6570\u5b57\u7b7e\u540d\u4f1a\u62a5\u9519\u3002\n\n\u4f7f\u7528\u7b80\u5355KEY\u8ba4\u8bc1\u7684\u65b9\u5f0f\u793a\u4f8b\uff1a\n\n```python\nconf = QWeatherConfig(self._domain,EnvironmentVariableSimpleAuthCredential())\nfactory = QWeatherFactory()\npack = factory.create_airquality_pack(conf)\nresp = pack.airquality_now('101090101')\nprint(resp.aqi)\n```\n\n## \u63a5\u53e3\u7684\u6620\u5c04\n\n\u5bf9\u5e94\u5b98\u7f51\u7684[\u63a5\u53e3\u5217\u8868](https://dev.qweather.com/docs/api/)\uff0c\u7ec4\u4ef6\u4e5f\u5b9a\u4e49\u4e86\u76f8\u5e94\u7684Package\u7c7b\uff0c \u4f60\u603b\u662f\u53ef\u4ee5\u901a\u8fc7\u5de5\u5382\u65b9\u6cd5 ```QWeatherFactory().create_xxx()```\u7684\u65b9\u5f0f\u521b\u5efa\u5bf9\u5e94\u7684API\u7c7b\uff08xxx\u8868\u793a\u4e0b\u8868\u7684Package\uff09\u3002\n\n\u5177\u4f53\u5bf9\u5e94\u5173\u7cfb\u5982\u4e0b\u8868\u6240\u793a\uff1a\n\n\n\n| \u63a5\u53e3\u5206\u7ec4 | Package | \n|----------| ---------- |\n| GeoAPI | geo_pack |\n| \u57ce\u5e02\u5929\u6c14 | weather_pack |\n| \u5206\u949f\u9884\u62a5 | minutely_pack |\n| \u683c\u70b9\u5929\u6c14 | grid_weather_pack |\n| \u9884\u8b66 | weather_warning_pack |\n| \u5929\u6c14\u6307\u6570 | indices_pack |\n| \u7a7a\u6c14\u8d28\u91cf(beta) | air_quality_pack | \n| \u7a7a\u6c14\u8d28\u91cf | air_pack |\n| \u65f6\u5149\u673a | time_machine_pack |\n| \u70ed\u5e26\u6c14\u65cb\uff08\u53f0\u98ce\uff09 | tropical_cyclone_pack | \n| \u6d77\u6d0b\u6570\u636e | ocean_pack |\n| \u592a\u9633\u8f90\u5c04 | solar_radiation_pack | \n| \u5929\u6587 | astronomy_pack |\n\n\n## \u66f4\u591a\u5185\u5bb9\n\n### [\u5b98\u65b9\u6587\u6863](https://dev.qweather.com/docs/start/)\n\n",
"bugtrack_url": null,
"license": null,
"summary": "\u548c\u98ce\u5929\u6c14 api for python3",
"version": "1.0.6",
"project_urls": {
"Homepage": "https://github.com/imaxu/py-qweather"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6de18468c3b09a6af9f6f98ac9663019277123a2b91484d7e496340a526d8bff",
"md5": "58033c4380f70d79d82070bcbcf7ed56",
"sha256": "63b26cd2cf7ca39128b120f942748b27f9dcfe69a99e7b344c1f7aa2103f3899"
},
"downloads": -1,
"filename": "pyqweather-1.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "58033c4380f70d79d82070bcbcf7ed56",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 43080,
"upload_time": "2024-08-09T07:07:05",
"upload_time_iso_8601": "2024-08-09T07:07:05.829751Z",
"url": "https://files.pythonhosted.org/packages/6d/e1/8468c3b09a6af9f6f98ac9663019277123a2b91484d7e496340a526d8bff/pyqweather-1.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "fca1c82572c3d5840477f99c2ee135084e3fcd5abbc6df757f711ee5df5c1870",
"md5": "629538b0d9bbfe8b3d781d95a577b373",
"sha256": "8bfe555f2f8fe5efb0892fce2d556cba0ae51ff2af1537340fcbff571d8aee39"
},
"downloads": -1,
"filename": "pyqweather-1.0.6.tar.gz",
"has_sig": false,
"md5_digest": "629538b0d9bbfe8b3d781d95a577b373",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 25644,
"upload_time": "2024-08-09T07:07:07",
"upload_time_iso_8601": "2024-08-09T07:07:07.631590Z",
"url": "https://files.pythonhosted.org/packages/fc/a1/c82572c3d5840477f99c2ee135084e3fcd5abbc6df757f711ee5df5c1870/pyqweather-1.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-09 07:07:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "imaxu",
"github_project": "py-qweather",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pyqweather"
}