利用Python发送天气预报信息到手机
来源:互联网 发布:21天学通linux c编程 编辑:程序博客网 时间:2024/05/10 04:40
#!/usr/bin/env python
#coding=utf-8
import urllib, urllib2
import re
import time
#from PyFetion import *
proxy=urllib2.ProxyHandler({'http': 'http://lk:2002@172.17.5.53:80'})
opener=urllib2.build_opener(proxy)
urllib2.install_opener(opener)
def GetWeather():
sock = urllib2.urlopen("http://qq.ip138.com/weather/guangdong/DongGuan.htm")
strhtml = sock.read()
strhtml = unicode(strhtml, 'gb2312','ignore').encode('utf-8','ignore')
#strhtml = unicode(strhtml, 'gb2312','ignore').encode('big5','ignore')
#print strhtml
theGrades = re.findall('<td>(.*℃)</td>', strhtml)
weathers = re.findall('<td><img src="/image/b/d+.gif" alt=".*" /><br/>(.*)</td>', strhtml)
# 定???格式
this_date = str(time.strftime("%Y/%m/%d %a"))
now = int(time.time())
sec = 24*60*60
day_today = "今天(%s號)" % str(time.strftime("%d", time.localtime(now+0*sec)))
day_tommo = "明天(%s號)" % str(time.strftime("%d", time.localtime(now+1*sec)))
day_aftom = "后天(%s號)" % str(time.strftime("%d", time.localtime(now+2*sec)))
# 定?短信正文
#sms = [this_date]
sms = []
sms.append("東莞天气")
sms.append("%s:%s, %s" % (day_today, weathers[0], theGrades[0]))
sms.append("%s:%s, %s" % (day_tommo, weathers[1], theGrades[1]))
sms.append("%s:%s, %s" % (day_aftom, weathers[2], theGrades[2]))
sms.append("天气有冷暖,關怀永不變!")
smscontent = '/n'.join(sms)
return smscontent
def SendSMS(sms):
myphone = '1365024****' # 手机号
mypwd = 'xxxx' # 登录密码
destphone = ["62487xxxx", "70078xxxx", "69451xxxx"] # 发送对象飞信号
# 发送目的地改为飞信号,之前用的手机号做目的地发送,别人的收不到短信
print "/nwaiting for login fetion..."
fetion = PyFetion(myphone, mypwd, 'TCP')
fetion.login(FetionHidden)
for phone in destphone:
print "sending to", phone
fetion.send_sms(sms, phone, True)
print "OK"
fetion.logout()
return True
def main():
print "getting out the weather code..."
msg = GetWeather()
print "/n", msg
#SendSMS("测试天气预报")
#SendSMS(msg)
print "Done."
if __name__ == "__main__":
main()
- 利用Python发送天气预报信息到手机
- Python发送天气预报信息到手机
- Python定时利用QQ邮件发送天气预报
- 利用飞信发送天气预报
- 利用ArcIMS Java客户端发送地图到手机
- 树莓派利用Instapush服务推送信息到手机
- 使用Python实现每日一句英语发送到手机
- zabbix 通过python脚本将报警信息发送到rabbitMQ
- 20120808ping脚本输出异常信息时进行报警,将信息发送到手机
- 利用python发送短信
- 利用python发送邮件
- 天气预报信息
- 发送信息到邮箱里
- 发送信息到URL上
- 保存信息到手机里
- 使用J2ME发送手机短信息
- 使用J2ME发送手机短信息
- 使用PDU串发送手机短信息
- Javascript URL 编码区别及转义字符处理
- 明确架构目标
- Oracle函数
- JNI编程 —— 让C++和Java相互调用
- AutomationQA.com开始连载《WEB-QTP随想录》
- 利用Python发送天气预报信息到手机
- GridView模板列中的TextBox的ontextchanged事件中获取当前行的某列!
- [原创]VS2008 工程改 vs2005/vs2003工程的图文教程
- js文字进行编码相关函数诠释
- 深有感触的文章 --- 小公司成长,大公司学习
- opencv学习-1.1-入门- 显示图片
- SQL Server 2005中数据库镜像的四个问题
- 关于ADS编译错误 error U1077 C:/Program 返回0x01 的解决办法
- 泰勒级数定义及相关展开式