Python发送天气预报信息到手机

该Python脚本抓取ip138网站的广东东莞天气信息,利用PyFetion库发送短信通知。程序首先获取网页源码,通过正则表达式提取温度和天气描述,然后构造短信内容并发送到指定的飞信号。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个程序很早以前就写过了,而且是参考的别人的写,具体谁的发
-*- coding:utf-8 -*-  

# file:weather.py  

# by Lee, 2010-1-11  

"""  

抓取天气预报信息,并通过pyfetion发送短信通知  

""" 

import os  
import re  
import urllib  
import sys  
import time  
from PyFetion import * 

    

def GetWeather():  

try:  

# 获取网页源文件  

sock = urllib.urlopen("http://qq.ip138.com/weather/guangdong/DongGuan.htm")  

strhtml = sock.read()  

strhtml = unicode(strhtml, 'gb2312','ignore').encode('utf-8','ignore')  

# 正则式取温度信息  

theGrades = re.findall('''(\d+)℃''', strhtml)  

# 获取天气描述信息  

weathers = re.findall('''  (.*)''',strhtml)  

25         # 定义时间格式  

26         this_date = str(time.strftime("%Y/%m/%d %a"))  

27         now = int(time.time())  

28         sec = 24*60*6
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值