From 04299f143bb813ad2ce36f4abfdcee22a1960780 Mon Sep 17 00:00:00 2001 From: RTAkland Date: Tue, 16 Nov 2021 21:48:27 +0800 Subject: [PATCH] edit: rename file name --- lib/get_warning_city_list.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lib/get_warning_city_list.py diff --git a/lib/get_warning_city_list.py b/lib/get_warning_city_list.py new file mode 100644 index 0000000..766079e --- /dev/null +++ b/lib/get_warning_city_list.py @@ -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']