import urllib3
import json
import urllib3
url = "https://api.seniverse.com/v3/weather/daily.json"
headers = {
"Accept": "application/json, text/plain, */*",
# "Accept-Encoding": "gzip, deflate",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36",
}
msgurl = "https://qmsg.zendee.cn/send/fdeeef3df1b6257753d9acd846e4e14a"
params = {
"key": "SQF5A3lnG_qSj4Mda",
"location": "宜昌",
"language": "zh-Hans",
"unit": 'c',
"start": 0,
"days": 3,
}
# requests.DEFAULT_RETRIES = 5
# s = requests.session()
# s.keep_alive = False
# s.headers = headers
# s.get(url)
http = urllib3.PoolManager()
r = http.request(
"GET",
url,
headers=headers,
fields=params
)
data = json.loads(r.data.decode())
print(data)
city = data["results"][0]["location"]["name"]
daily = data["results"][0]["daily"]
text = "城市:湖北省" + city + "市" + '\n'
# print(daily[0]["date"])
for i in range(3):
date = daily[i]["date"] # 日期
high = daily[i]["high"] # 最高温度
low = daily[i]["low"] # 最低温度
day_weather = daily[i]["text_day"] # 日间气温
night_weather = daily[i]["text_night"] # 夜间气温
wind_speed = daily[i]["wind_speed"] # 风速
wind_scale = daily[i]["wind_scale"] # 风速级别
precip = daily[i]["precip"] # 降雨概率
text += ("日期:" + date + '\n')
text += ("当日最高温度:" + high + "C°" + '\n')
text += ("当日最低气温:" + low + "摄氏度" + '\n')
text += ("日间气温:" + day_weather + '\n')
text += ("夜间气温:" + night_weather+ '\n')
text += ("风速:" + wind_speed + "km/h" + '\n')
text += ("风力级别:" + wind_scale + "级" + '\n')
text += ("降雨概率:" + precip + '\n')
text += '\n'
print()
print(text)
qq = "54535282"
msgRequest = http.request(
"POST",
msgurl,
fields = {
"msg": text,
"qq": qq,
}
)
print(msgRequest.data.decode())