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_real_time_air_quality.py

39 lines
1.1 KiB
Python
Raw Normal View History

2021-12-04 14:04:46 +08:00
#!/usr/bin/env python3
2021-11-11 21:23:15 +08:00
# -*- coding: utf-8 -*-
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2021/9/29
# @File Name: API_real_time_air_quality.py
"""
开发版key获取实时空气质量
2021-11-18 21:27:16 +08:00
启用等级: DEV
2021-11-11 21:23:15 +08:00
"""
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']