Thu Mar 26 09:18:15 2009
decompile /tmp/upload/20090326091815_427.pyc...
#! /usr/bin/env python
# emacs-mode: -*- python-*-
# -*- coding: utf-8 -*-
import os
import sys
import os.path
import datetime
import urllib
import smtplib
import email
import hashlib
urlbase = ''
cities = {'\xe8\x8b\x8f\xe5\xb7\x9e': '101190401',
'\xe5\xbe\x90\xe5\xb7\x9e': '101190801',
'\xe5\x8d\x97\xe4\xba\xac': '101190101'}
def rm_pages(city):
localfile = (city + '.shtml')
if os.path.isfile(localfile):
cmd = ('rm -f ./%s' % localfile)
os.popen(cmd)
def get_message(city):
url = ((urlbase + cities[city]) + '.shtml')
localfile = (city + '.shtml')
try:
urllib.urlretrieve(url, localfile)
except IOError:
urllib.urlretrieve(url, localfile)
cmd = ("sed -i -e '1,/c_1_1/d; /c_1_2/,/dd_0/d; /surf/,$d; /\xe7\xb4\xab\xe5\xa4\x96\xe7\xba\xbf/,/\xe8\x88\x92\xe9\x80\x82\xe6\x8c\x87\xe6\x95\xb0/d' %s" % localfile)
os.popen(cmd)
cmd = ("sed -i -e 's/<[^>]*>//g;/  /d' %s" % localfile)
os.popen(cmd)
cmd = ("sed -i -e 's/^\\s*//g;/^$/d' %s" % localfile)
os.popen(cmd)
cmd = ("sed -i -e 's/\\/ / -/g;s/\xe6\x98\x9f\xe6\x9c\x9f.*//g;s/\xe9\xab\x98\xe6\xb8\xa9\xef\xbc\x9a//g;s/\xe4\xbd\x8e\xe6\xb8\xa9\xef\xbc\x9a//g' %s" % localfile)
os.popen(cmd)
message = (city + '\xe6\x9c\xaa\xe6\x9d\xa5\xe4\xb8\x89\xe5\xa4\xa9\xe7\x9a\x84\xe5\xa4\xa9\xe6\xb0\x94:\n')
tomorrow = ('%s\xe6\x97\xa5: ' % (int(datetime.date.today().day) + 1))
f = open(localfile)
message += (((tomorrow + f.readline().replace('\r\n', ',')) + f.readline().replace('\r\n', ' ,')) + f.readline())
message += (f.readline().replace('\n', ': ') + f.readline().replace('\r\n', ','))
htemp = f.readline().replace('\r\n', ' ,')
ltemp = f.readline().replace('\r\n', '')
message += ((ltemp + ' -') + htemp)
message += f.readline()
message += (f.readline().replace('\n', ': ') + f.readline().replace('\r\n', ','))
htemp = f.readline().replace('\r\n', ' ,')
ltemp = f.readline().replace('\r\n', '')
message += ((ltemp + ' -') + htemp)
message += f.readline()
f.close()
print message
return message
def send_mail(send_from, send_to, subject, text, auth = (), send_server = 'localhost'):
msg = email.MIMEMultipart.MIMEMultipart()
msg['From'] = send_from
msg['To'] = email.Utils.COMMASPACE.join(send_to)
msg['Date'] = email.Utils.formatdate(localtime=True)
msg['Subject'] = email.Header.Header(subject, 'utf-8')
msg.attach(email.MIMEText.MIMEText(text, _subtype='plain', _charset='utf-8'))
smtp = smtplib.SMTP(send_server)
smtp.docmd('EHLO server')
smtp.starttls()
smtp.login(*auth)
smtp.sendmail(send_from, send_to, msg.as_string())
smtp.close()
if (__name__ == '__main__'):
weather_msg = ''
for city in cities.keys():
weather_msg += get_message(city)
send_mail('gx2008758@gmail.com', ['bestfriends@gmail.com',
'sisters@sina.com',
'gx2008758@gmail.com'], '^_^\xe5\xa4\xa9\xe6\xb0\x94\xe9\xa2\x84\xe6\x8a\xa5^_^', weather_msg, ('gx2008758@gmail.com', 'uguessit'), 'smtp.gmail.com')
print 'Done.'
# local variables:
# tab-width: 4
depythoned 1 files: 1 okay, 0 failed
Thu Mar 26 09:18:16 2009
|