首页 技术 正文
技术 2022年11月14日
0 收藏 668 点赞 5,112 浏览 1592 个字
from email.mime.text import MIMEText
from email.header import Header
from smtplib import SMTP_SSLimport urllib.request
import timedef get_weather_msg():
page = urllib.request.urlopen("http://www.weather.com.cn/weather/101200101.shtml")
text = page.read().decode("utf8")
#print(text)
startNum = text.find("(今天)</h1>")
endNum = text.find("(明天)</h1>")
text = text[startNum-3:endNum]
#print(text)
date = text[0:3]
#print("**************")
startNum = text.find("class=\"wea\">")
endNum = text.find("<p class=\"tem\">")
weather = text[startNum+12:endNum-5] startNum = text.find("<p class=\"tem\">")
endNum = text.find("℃</i>")
tempreture = text[endNum-2:endNum] message = ("今天" + date + "\n" + "天气:"+ weather+ "\n" + "温度:"+ tempreture +"℃" + "\n")
tempreture = float(tempreture)
if tempreture > 30:
message = message + "高温"
elif tempreture < 10:
message = message + "低温"
else:
message = message + "温度适中" #print("今天" + date)
#print("天气:"+ weather)
#print("温度:"+ tempreture +"℃")
return (message)def send_weather_by_mail(content):
#qq邮箱smtp服务器
host_server = 'smtp.qq.com'
#sender_qq为发件人的qq号码
sender_qq = '150xxxxx'
#pwd为qq邮箱的授权码
pwd = 'Lxxxxx'
#发件人的邮箱
sender_qq_mail = '150xxxxx@qq.com'
#收件人邮箱
receiver = 'xxxxx@xxxx.com'
#邮件的正文内容
mail_content = content
#邮件标题
mail_title = 'xxx的邮件' #ssl登录
smtp = SMTP_SSL(host_server)
#set_debuglevel()是用来调试的。参数值为1表示开启调试模式,参数值为0关闭调试模式
smtp.set_debuglevel(0)
smtp.ehlo(host_server)
smtp.login(sender_qq, pwd) msg = MIMEText(mail_content, "plain", 'utf-8')
msg["Subject"] = Header(mail_title, 'utf-8')
msg["From"] = sender_qq_mail
msg["To"] = receiver
smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
smtp.quit() checkTime = 0
while 1:
checkTime += 1
send_weather_by_mail(get_weather_msg())
print(">>>"+str(checkTime)+">>>")
time.sleep(10)
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918