扫一扫,手机访问本帖
|
抓到你想要的deal自动给你发email或短消息,有兴趣的下去改了用。直接拷贝下面这
段code修改后存为sac.py,然后运行python sac.py即可。在python 2.7下测试通过。
#!/usr/bin/python
import re
import urllib
import smtplib
import time
from email.mime.text import MIMEText
target=[['trekking', 'poles'],['Napali', 'Backpack'],['north', 'face'],['
oakley','battalion']] #The items you want to monitor, in every set of [] AND
logical will be used to match a specific item
discount_threshold=50 #threshold of percentage to trigger event
check_interval=60 #the interval to refresh in unit of second
hourstart=8 #what time you want this start to send you sms by hour
hourstop=22 #waht time you want this to stop by hour
smtpserver='smtp.mail.yahoo.com' #smtp email server you want to use
smtpport=25 # port number of smtp server
fromadd='someone@yahoo.com' #email sender address
toadd='6268888888@tmomail.net' #email recipent address, use cellphone sms
gateway address to send sms to your cellphone
user='someone' #put your email account name here
passwd='xxxxxx' #put your email account passwd here
oldinfoline=''
while True:
ctime=time.localtime()[3]
if ctime>hourstart and ctime<hourstop:
a=urllib.urlopen('http://www.steepandcheap.com')
lines=a.readlines()
item_m=re.compile('<title>Steep and Cheap:')
discount_m=re.compile('discount:')
price_m=re.compile('price:')
#infoline='<title>Steep and Cheap: Mountain Hardwear Napali 50
Backpack - 2850-3050cu in - Womens - $69.99 - 63% off<title>\n'
for line in lines:
line=line.strip()
if item_m.match(line):
infoline=line
if discount_m.match(line):
discountline=line
if price_m.match(line):
priceline=line
if infoline!=oldinfoline:
oldinfoline=infoline
outmsg=''
n_match=re.compile('\d+\.*\d*')
price=float((n_match.search(priceline)).group())
discount=float((n_match.search(discountline)).group())
infoline2=infoline.upper()
match=0
for tr in target:
test=1
for trf in tr:
if infoline2.find(trf.upper())<0:
test=0
if test==1:
match=1
for tar in tr:
outmsg+=tar
outmsg+=' '
outmsg+='$'
outmsg+=str(price)
break
info=infoline[7:][:-8]
if match==1:
em=smtplib.SMTP(smtpserver,smtpport)
em.login(user,passwd)
msg=MIMEText(info)
msg['Subject']=outmsg #squeeze so you don't need to download
the actual message
msg['From']=fromadd
msg['To']=toadd
em.sendmail(fromadd,toadd,msg.as_string())
em.quit()
time.sleep(check_interval) |
|