易截截图软件、单文件、免安装、纯绿色、仅160KB

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"))
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.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], theG


相关文档:

用 python 快速搭建网游服务器

赖勇浩(http://laiyonghao.com)
今天(2009年5月31日) OurPNP.org 搞了个聚会活动,弄了十几二十个人在广州海珠广场的堂会呆了五个小时,创下了我在 K 房呆的最长时间纪录。应他们的邀请,我做了个题为《用 python 快速搭建网游服务器》的小演讲,因为那边的电视竟然不能接电脑,所以讲的时候没有能够参照 PPT 来讲,观 ......

python天天进步(2) 文件操作之遍历目录

 
Python的os模块,包含了普遍的操作系统功能,这里主要学习与路径相关的函数:
os.listdir(dirname):列出dirname下的目录和文件
os.getcwd():获得当前工作目录
os.curdir:返回当前目录('.')
os.chdir(dirname):改变工作目录到dirname
os.path.isdir(name):判断name是不是一个目录,name不是目录就返回false ......

[Python module] threading

threading — Higher-level threading interface
This module constructs higher-level threading interfaces on top of the lower level _thread module. See also the queue module.
The dummy_threading module is provided for situations where threading cannot be used because _thread is missing.
  ......

写了几个有关operaminimod的python小程序

写了几个有关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=[]
  ......

[转]Python: python编码问题

这是一个我们在处理中文时, 经常遇到的问题.
python里面基本上要考虑三种编码格式
1 源文件编码
在文件头部使用coding声明。告诉python解释器该代码文件所使用的字符集。
#/usr/bin/python
#coding: utf8
2 内部编码
代码文件中的字符串,经过decode以后,被转换为统一的unicode格式的内部数据,类似于u'*'。unic ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号