1. import urllib3
    2. import json
    3. import urllib3
    4. url = "https://api.seniverse.com/v3/weather/daily.json"
    5. headers = {
    6. "Accept": "application/json, text/plain, */*",
    7. # "Accept-Encoding": "gzip, deflate",
    8. "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",
    9. }
    10. msgurl = "https://qmsg.zendee.cn/send/fdeeef3df1b6257753d9acd846e4e14a"
    11. params = {
    12. "key": "SQF5A3lnG_qSj4Mda",
    13. "location": "宜昌",
    14. "language": "zh-Hans",
    15. "unit": 'c',
    16. "start": 0,
    17. "days": 3,
    18. }
    19. # requests.DEFAULT_RETRIES = 5
    20. # s = requests.session()
    21. # s.keep_alive = False
    22. # s.headers = headers
    23. # s.get(url)
    24. http = urllib3.PoolManager()
    25. r = http.request(
    26. "GET",
    27. url,
    28. headers=headers,
    29. fields=params
    30. )
    31. data = json.loads(r.data.decode())
    32. print(data)
    33. city = data["results"][0]["location"]["name"]
    34. daily = data["results"][0]["daily"]
    35. text = "城市:湖北省" + city + "市" + '\n'
    36. # print(daily[0]["date"])
    37. for i in range(3):
    38. date = daily[i]["date"] # 日期
    39. high = daily[i]["high"] # 最高温度
    40. low = daily[i]["low"] # 最低温度
    41. day_weather = daily[i]["text_day"] # 日间气温
    42. night_weather = daily[i]["text_night"] # 夜间气温
    43. wind_speed = daily[i]["wind_speed"] # 风速
    44. wind_scale = daily[i]["wind_scale"] # 风速级别
    45. precip = daily[i]["precip"] # 降雨概率
    46. text += ("日期:" + date + '\n')
    47. text += ("当日最高温度:" + high + "C°" + '\n')
    48. text += ("当日最低气温:" + low + "摄氏度" + '\n')
    49. text += ("日间气温:" + day_weather + '\n')
    50. text += ("夜间气温:" + night_weather+ '\n')
    51. text += ("风速:" + wind_speed + "km/h" + '\n')
    52. text += ("风力级别:" + wind_scale + "级" + '\n')
    53. text += ("降雨概率:" + precip + '\n')
    54. text += '\n'
    55. print()
    56. print(text)
    57. qq = "54535282"
    58. msgRequest = http.request(
    59. "POST",
    60. msgurl,
    61. fields = {
    62. "msg": text,
    63. "qq": qq,
    64. }
    65. )
    66. print(msgRequest.data.decode())