Advertisement
Guest User

Untitled

a guest
May 7th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import threading
  5. import urllib2
  6. import smtplib
  7.  
  8.  
  9. def send_email():
  10.     gmail_user = "oteugmail@gmail.com" #edit
  11.     gmail_pwd = "tuapass" #edit
  12.     FROM = 'oteugmail@gmail.com' #edit
  13.     TO = ['oteugmail@gmail.com'] #edit
  14.    
  15.     SUBJECT = "Bilhetes Final da Taรงa"
  16.     TEXT = "Vai comprar imediatamente !!!"
  17.  
  18.     message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
  19.    """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
  20.     try:
  21.         server = smtplib.SMTP("smtp.gmail.com", 587)
  22.         server.ehlo()
  23.         server.starttls()
  24.         server.login(gmail_user, gmail_pwd)
  25.         server.sendmail(FROM, TO, message)
  26.         server.close()
  27.         print 'successfully sent the mail'
  28.     except:
  29.         print "failed to send mail"
  30.  
  31. def checkit():
  32.     threading.Timer(300.0, checkit).start() #5 min
  33.     req = urllib2.Request('https://bilheteira.fpf.pt')
  34.     response = urllib2.urlopen(req)
  35.     html = response.read()
  36.  
  37.     if(html.lower().find('taรงa de portugal') != -1 or html.lower().find('benfica') != -1):
  38.       send_email()
  39.  
  40. checkit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement