boren -学习使用python查看天气预报并按时发送给好友

import requests,json
import city
import datetime
now = datetime.datetime.now()
while True:
    if now.hour == 7 and now.minute == 00:
        # in 里面  put 放在   input
        cityname = input("你想查找哪个城市")
        cc = city.citycode[cityname]
        wangzhi = "http://t.weather.sojson.com/api/weather/city/%s"%cc
        # wangzhi = "http://t.weather.sojson.com/api/weather/city/"+cc
        response=requests.get(wangzhi)
        a=response.json()
        # print(a)
        # print(a.keys())
        # print(a['data'].keys())

        b= "城市:"+a["cityInfo"]["city"]+\
            "\n时间:"+a["time"]+\
           "\n温度:"+a["data"]["wendu"]+\
           "\n空气质量:"+a["data"]["quality"]
        print(b)
    if now.hour == 1 and now.minute == 00:
        print("发送晚安")








发布了254 篇原创文章 · 获赞 16 · 访问量 9493

猜你喜欢

转载自blog.csdn.net/houlaos/article/details/104036277
今日推荐