You've already forked QWeatherReporter
upload via files
This commit is contained in:
26
module/API_24hour_weathers.py
Normal file
26
module/API_24hour_weathers.py
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
# -- coding:utf-8 --
|
||||
# @Author: markushammered@gmail.com
|
||||
# @Development Tool: PyCharm
|
||||
# @Create Time: 2021/10/31
|
||||
# @File Name: API_24hour_weathers.py
|
||||
|
||||
"""
|
||||
获取未来24小时时级天气预报 (24)
|
||||
启用等级: DEV
|
||||
"""
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
|
||||
def hourly_weather(location: int, key: str, lang: str = 'zh', unit: str = 'm'):
|
||||
r = requests.get(
|
||||
f'https://devapi.qweather.com/v7/weather/24h?location={location}&key={key}&lang={lang}&unit={unit}')
|
||||
data = json.loads(r.text)
|
||||
|
||||
status_code = data['code']
|
||||
updateTime = str(data['updateTime'][:-6]).replace('T', '')
|
||||
main_data = data['hourly'] # 24
|
||||
return status_code, updateTime, main_data
|
||||
|
||||
26
module/API_Indices.py
Normal file
26
module/API_Indices.py
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
# -- coding:utf-8 --
|
||||
# @Author: markushammered@gmail.com
|
||||
# @Development Tool: PyCharm
|
||||
# @Create Time: 2021/10/31
|
||||
# @File Name: API_indices.py
|
||||
|
||||
"""
|
||||
获取生活建议的API
|
||||
获取所有生活建议 (15+)
|
||||
启用等级: DEV
|
||||
"""
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
|
||||
def indices(location: int, key: str, lang: str = 'zh', unit: str = 'm'):
|
||||
r = requests.get(
|
||||
f'https://devapi.qweather.com/v7/indices/1d?type=0&location={location}&key={key}&lang={lang}&unit={unit}')
|
||||
data = json.loads(r.text)
|
||||
status_code = data['code']
|
||||
updateTime = str(data['updateTime'][:-6]).replace('T', '')
|
||||
main_data = data['daily'] # 1-15(+)
|
||||
return status_code, updateTime, main_data
|
||||
|
||||
27
module/API_get_warning_list.py
Normal file
27
module/API_get_warning_list.py
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author: markushammered@gmail.com
|
||||
# @Development Tool: PyCharm
|
||||
# @Create Time: 2021/9/29
|
||||
# @File Name: API_get_warning_list.py:
|
||||
|
||||
"""
|
||||
开发版key使用此API可以快速返回正在预警的城市id
|
||||
Only Dev-mode
|
||||
"""
|
||||
|
||||
import requests
|
||||
import json
|
||||
from ruamel.yaml import YAML
|
||||
|
||||
|
||||
def get_warning_list(_range='cn'):
|
||||
yaml = YAML()
|
||||
with open('./config.yml', 'r', encoding='utf-8') as f:
|
||||
config = yaml.load(f.read())
|
||||
key = config['request-settings']['key']
|
||||
session = requests.Session()
|
||||
session.trust_env = False
|
||||
r = session.get(f'https://devapi.qweather.com/v7/warning/list?range={_range}&key={key}')
|
||||
_data = json.loads(r.text)
|
||||
return _data['code'], _data['warningLocList'][0]['locationId']
|
||||
38
module/API_real_time_air_quality.py
Normal file
38
module/API_real_time_air_quality.py
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author: markushammered@gmail.com
|
||||
# @Development Tool: PyCharm
|
||||
# @Create Time: 2021/9/29
|
||||
# @File Name: API_real_time_air_quality.py
|
||||
|
||||
"""
|
||||
开发版key获取实时空气质量
|
||||
only: Dev-mode
|
||||
"""
|
||||
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
from ruamel.yaml import YAML
|
||||
|
||||
|
||||
def real_time_air_quality():
|
||||
yaml = YAML()
|
||||
with open(sys.path[1] + '/config.yml', 'r', encoding='utf-8') as f:
|
||||
config = yaml.load(f.read())
|
||||
|
||||
mode = config['request-settings']['mode']
|
||||
key = config['request-settings']['key']
|
||||
location = config['request-settings']['location']
|
||||
unit = config['request-settings']['unit']
|
||||
lang = config['request-settings']['lang']
|
||||
|
||||
if mode != 'dev':
|
||||
return False, print('Only Dev-mode')
|
||||
session = requests.Session()
|
||||
session.trust_env = False
|
||||
r = session.get(f'https://devapi.qweather.com/v7/air/now?'
|
||||
f'location={location}config.yml&key={key}&lang={lang}&unit={unit}&gzip=y')
|
||||
_data = json.loads(r.text)
|
||||
|
||||
return _data['code'], _data['now']
|
||||
6
module/__init__.py
Normal file
6
module/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author: markushammered@gmail.com
|
||||
# @Development Tool: PyCharm
|
||||
# @Create Time: 2021/10/16
|
||||
# @File Name: __init__.py
|
||||
Reference in New Issue
Block a user