python天气查询练手案例

源码说明

一、说明

本项目是使用PyQt+Requets+正则表达式实现的天气查询程序,总共有100行左右,如果在研究过程中遇到任何问题都可以添加 王老师微信 dong4716138进行交流

查询天气 源码下载:

0b7590d6bf71c4d5d1455e583ee08fe2.png

长按左侧二维码 2 秒

回复「天气」即可获取源码

(非本号)

项目视频讲解地址:https://www.bilibili.com/video/BV1Jh411Y7ib/

二、运行效果

运行之后的 效果

2dc04b83cdc0d3532b611af942edd647.png

可以输入要查询的天气的城市

5680e3f9b1fa6960f60ec5a5a6a39991.png

查询的结果

b6a18d4484253c129519f53a6ce41bae.png

三、部分代码示例

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)

查询天气 源码下载:

a6f4bf3515312a371337f8ba910000b0.png

长按左侧二维码 2 秒

回复「天气」即可获取源码

(非本号)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

曾亲桂林

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值