#!/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><br/> (. *) </td> ', strhtml)
# set??? Format
This_date = str (time.strftime ("%y/%m/%d%a"))
now = Int (Time.time ())
SEC = 24*60*60
Day_today = "Today (%s)"% str (time.strftime ("%d", Time.localtime (NOW+0*SEC))
Day_tommo = "Tomorrow (%s)"% str (time.strftime ("%d", Time.localtime (NOW+1*SEC))
Day_aftom = "Acquired (%s)"% str (time.strftime ("%d", Time.localtime (NOW+2*SEC))
# set? text message
#sms = [This_date]
SMS = []
Sms.append ("East of the Weather")
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 ("The weather has warm and cold, the bosom will never change!")
Smscontent = '/n '. Join (SMS)
Return smscontent
def sendsms (SMS):
Myphone = ' 1365024**** ' # mobile number
MyPwd = ' xxxx ' # login password
Destphone = ["62487xxxx", "70078xxxx", "69451xxxx"] # Send object fly signal
# Send the destination to fly signal, before using the mobile phone number to send the destination, others do not receive text messages
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 ("Test weather Forecast")
#SendSMS (msg)
Print "Done."
if __name__ = = "__main__":
Main ()