获取天气质量指数
"""
json
tianqi.com
"""
import requests
# 发起 GET 请求
# json_data = {'code': 200, 'msg': 'success', 'result': {'area': '上海', 'area_code': 'yangzhou', 'so2': '8', 'o3': '68', 'pm2_5': '14', 'primary_pollutant': '', 'co': '0.5', 'num': '96', 'no2': '21', 'quality': '优质', 'aqi': '35', 'pm10': '38', 'o3_8h': '57', 'time': '2024-01-15 16:10:00.014'}}
area = "上海"
response = requests.get(
url="https://apis.tianapi.com/aqi/index",
params={'key':'yourkey','area':area}
)
#检查请求是否成功
if response.status_code == 200:
#获取 JSON 数据
json_data = response.json()
#print(json_data)
print(f"{area}空气质量:",json_data["result"]["quality"],",空气质量指数(AQI):",json_data["result"]["aqi"])
else:
print('请求失败:', response.status_code)