Python发送天气预报信息到手机
writeblog.csdn.net writeblog.csdn.net/PostEdit.aspx
这个程序很早以前就写过了,而且是参考的别人的写,具体谁的发在哪里我都忘记了。这里就算是半原创了,如有侵权请及时通知改正。
因为从今天1月1号开始,Google上订阅的天气预报服务已经取消了,估计是Google被施加压力了。反正是收不到天气预报了。正好重拾以前的那个脚本,自己设置抓取信息并发到手机就行了。
之前的脚本是用Python写的,抓的是新浪天气预报页面的信息,使用cocobear提供的PyFetion发送到自己手机上。上周拿来一运行,报error...
原来是飞信平台升级了,PyFetion也跟着升级了,而且新浪天气预报的页面也改版了。好嘛。。。
换用ip138提取的天气信息,重新改写如下
# -*- 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('''<br/>(.*)</td>''',strhtml)
# 定义时间格式
this_date = str(time.strftime("%Y/%m/%d %a"))
day_today = "今天(%s号)" % str(int(time.strftime("%d")))
day_tommo = "明天(%s号)" % str(int(time.strftime("%d")) + 1)
day_aftom = "后天(%s号)" % str(int(time.strftime("%d")) + 2)
# 定义短信正文
sms = [this_date]
sms.append("东莞天气")
sms.append("%s:%s, %s-%s℃" % (day_today, weathers[0], theGrades[1], theGrades[0]))
sms.append("%s:%s, %s-%s℃" % (day_tommo, weathers[1], theGrades[3], theGrades[2]))
sms.append("%s:%s, %s-%s℃" % (day_aftom, weathers[2], theGrades[5], theGrades[4]))
sms.append("天气有冷暖,关怀永不变!")
#sms.append("测试中,收到请MSN回复我,谢谢~~"
相关文档:
对数据库的操作基本分为三步:
连接数据库
根据需要执行SQL语句,接受返回值
关闭连接
我们正常的数据库应该都离不开这三步,下来说说如何使用python中的MySQLdb模块进行这些操作:
首先,我们需要把MySQLdb引入到程序中
import MySQLdb
然后开始数据库操作
1.数据库连接
conn = MySQLdb. ......
真是倒霉,刚买不久的移动硬盘,昨天删除一个分区失败后,几个分区都不见了,拿去修,未果
换了个新的,但其中数据全没了。那是我平时收集的很有用的资料
很多都可以重新下载,但怎能想起硬盘中的所有东西
今天换硬盘回来
就像写一个保存指定路径下所有文件夹和文件名的程序
这样,如果东西丢了,看看那里有些什么,也 ......
16.1. select — Waiting for I/O completion¶
This module provides access to the select and poll functions available in most operating systems, epoll available on Linux 2.5+ and kqueue available on most BSD. Note that on Windows, it only works for sockets; on other operating systems, it al ......
写了几个有关operaminimod的python小程序
firefox->opm书签转换
import re
def pipeiwangzhi(a):
s=[]
pp= re.compile(r'<DT><A HREF="(.*)" ADD_DATE=(.*>)(.*)</A>')
m=pp.search(a)
s1=[]
  ......