1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import requests
from datetime import datetime
city = "Guangzhou"
url = f"https://wttr.in/{city}?format=j1"
response = requests.get(url)
data = response.json()
# 读取当天的天气信息
today = data["weather"][0]
temp = today["avgtempC"]
weather_desc = today["hourly"][4]["weatherDesc"][0]["value"] # 白天中间时段为主
print("当前时间:", datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
print(f"广州今日平均温度:{temp}°C")
print(f"天气状况:{weather_desc}")