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

37 lines
899 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/10/31
# @File Name: API_24hour_weathers.py
"""
获取未来24小时时级天气预报 (24)
启用等级: DEV
"""
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
2021-12-18 19:44:12 +08:00
def hourly_weather():
2021-12-20 21:23:57 +08:00
"""
获取24小时的天气
:return:
"""
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
r = requests.get(
f'https://devapi.qweather.com/v7/weather/24h?location={location}&key={key}&lang={lang}&unit={unit}')
data = json.loads(r.text)
status_code = data['code']
2021-12-18 19:44:12 +08:00
updateTime = str(data['updateTime'][:-6])[10:].replace('T', '')
2021-11-11 21:23:15 +08:00
main_data = data['hourly'] # 24
return status_code, updateTime, main_data