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

30 lines
712 B
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
"""
2021-12-18 19:44:12 +08:00
from core.read_config import read_config
2021-11-11 21:23:15 +08:00
import requests
import json
def real_time_air_quality():
2021-12-18 19:44:12 +08:00
settings = read_config()
location = settings[1]['location']
key = settings[1]['key']
lang = settings[1]['lang']
unit = settings[1]['unit']
2021-11-11 21:23:15 +08:00
2021-12-18 19:44:12 +08:00
r = requests.get(f'https://devapi.qweather.com/v7/air/now?'
f'location={location}&key={key}&lang={lang}&unit={unit}&gzip=y')
2021-11-11 21:23:15 +08:00
_data = json.loads(r.text)
2021-12-18 19:44:12 +08:00
return _data['now']