This repository has been archived on 2025-12-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
QWeatherReporter/lib/get_warning_city_list.py

28 lines
781 B
Python
Raw Permalink Normal View History

2021-12-04 14:04:46 +08:00
#!/usr/bin/env python3
2021-11-16 21:48:27 +08:00
# -*- 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
2021-11-18 21:27:16 +08:00
启用等级: DEV
2021-11-16 21:48:27 +08:00
"""
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']