源码说明
一、说明
本项目是使用PyQt+Requets+正则表达式实现的天气查询程序,总共有100行左右,如果在研究过程中遇到任何问题都可以添加 王老师微信 dong4716138进行交流
查询天气 源码下载:
长按左侧二维码 2 秒 回复「天气」即可获取源码 (非本号) |
项目视频讲解地址:https://www.bilibili.com/video/BV1Jh411Y7ib/
二、运行效果
运行之后的 效果
可以输入要查询的天气的城市
查询的结果
三、部分代码示例
def find_weather(self):
"""发送查询请求"""
city_name = self.textbox.text()
weather_url = 'http://wthrcdn.etouch.cn/weather_mini?city={}'.format(city_name)
city_response = requests.get(weather_url, headers=headers)
weather_dict = json.loads(city_response.text)
if weather_dict.get('desc') == 'invilad-citykey':
self.wrong_city()
elif weather_dict.get('desc') == 'OK':
forecast_weather = weather_dict.get('data').get('forecast')
ganmao = weather_dict.get('data').get('ganmao')
day = []
for i in range(5):
tips_info = '日期:'
tips_info += forecast_weather[i].get('date') + '\n'
tips_info += '最高温度:' + forecast_weather[i].get('high') + '\n'
tips_info += '最低温度:' + forecast_weather[i].get('low') + '\n'
tips_info += '风向:' + forecast_weather[i].get('fengxiang') + '\n'
tips_info += '风力:' + reform_fl(forecast_weather[i].get('fengli')) + '\n'
tips_info += '天气状况:' + forecast_weather[i].get('type') + '\n'
day.append(tips_info)
show_weather.show_ui(city=city_name, info=ganmao, day=day)
查询天气 源码下载:
长按左侧二维码 2 秒 回复「天气」即可获取源码 (非本号) |