import easygui as gui
import requests
import city
# input
cityname = gui.enterbox('你想查找哪个城市')
chengshi = city.citycode[cityname]
url = 'http://t.weather.sojson.com/api/weather/city/'+chengshi
response = requests.get(url)
# 字符串转字典
d = response.json()
# print(d)
# print(type(d))
# print(d['message'])
message = "city:"+ d['cityInfo']['city'] + \
"\ntemperature:" + d['data']['wendu']
# print(message)
# print(d['data'])
# 查找天气预报:1.网站 2. 界面化软件(easygui/tkinter) 3. 定时发送信息
# 输入文字 enter box
# 显示文字 message box
gui.msgbox(message)
runze - 学习爬去天气预报
最新推荐文章于 2022-10-21 00:08:09 发布