runze - 学习爬去天气预报

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)
发布了516 篇原创文章 · 获赞 21 · 访问量 2万+

猜你喜欢

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