Advertisement
Guest User

A Simple Web Page Monitor

a guest
Nov 6th, 2017
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. """
  2.   A simple webpage monitor
  3.   Author: Samuel Pell
  4. """
  5.  
  6. import requests as req
  7. import sys
  8. import smtplib
  9. from email.mime.text import MIMEText
  10.  
  11. USER = "" #put sender email here //it assumes you are using gmail
  12. URL = "https://www.hoyts.co.nz/movies/coming_soon.aspx"
  13. PASSWORD = "" #password for the email account
  14. SEARCH_TERM = "fireworks"
  15.  
  16. def get_page(url):
  17.     try:
  18.         response = req.request('GET', url)
  19.         return response.content
  20.     except req.exceptions.ConnectionError:
  21.         sys.exit("Error")
  22.  
  23.  
  24. def send_email():
  25.     msg = MIMEText("""The word {} has been found on the Hoyts Coming Soon page
  26.    - With Love,
  27.  
  28.    Bot-chan""".format(SEARCH_TERM.title()))
  29.  
  30.     msg['From'] = #put sender email here
  31.     msg['Subject'] = "!!{} Alert!!".format(SEARCH_TERM.title())
  32.     msg['To'] = ''#put recipient email here
  33.  
  34.     s = smtplib.SMTP(host='smtp.gmail.com', port=587)
  35.     s.starttls()
  36.     s.login(USER, PASSWORD)
  37.     s.send_message(msg)
  38.     s.quit()
  39.  
  40.  
  41. def main():
  42.     web_page = get_page(URL)
  43.     web_page = str(web_page).lower()
  44.     isFound = web_page.find(SEARCH_TERM);
  45.  
  46.     if isFound != -1:
  47.         print("Search term was found, sending email...")
  48.         send_email()
  49.         print("email sent :)")
  50.     else:
  51.         print("Search term was not found :(")
  52.  
  53.  
  54. if __name__ == "__main__":
  55.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement