Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. import smtplib, requests
  2. from BeautifulSoup import BeautifulSoup as bs
  3. import time
  4.  
  5. header = {"User-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36"}
  6. url = 'http://www.westernmassnews.com/category/211531/storm-closings'
  7. lookFor = 'Holyoke Schools'
  8. username = '***@gmail.com'
  9. password = '******'
  10. eMail = 'staff@***.com'
  11. numbers = ['413*******@tmomail.net']
  12.  
  13. def soup(url):
  14. # REQUEST SITE, RETURN PARSED HTML
  15. site = requests.get(url, headers = header).text
  16. soup = bs(site)
  17. return soup
  18.  
  19. def findHolyoke(soup):
  20. # LOOK FOR STRING IN 'all_closings' DIV. IF FOUND, FIRE
  21. # OFF EMAIL AND SMS
  22.  
  23. try:
  24. findings = soup.find('div', id = 'all_closings').text
  25. except AttributeError:
  26. print "Didn't find anything!"
  27. return 0
  28.  
  29. if lookFor in findings:
  30. count = 1
  31. for num in numbers:
  32. print 'SMS # ' + str(count) + ' sent to ' + str(num)
  33. sms(num, 'School is closed, or has a delay today due to inclement weather. Please check local news for more info.')
  34. count += 1
  35. print 'eMail Sent to staff@****.com!'
  36. sendemail(eMail, 'School is closed, or has a delay today due to inclement weather. Please check local news for more info. ')
  37. else:
  38. # print 'Holyoke Schools not found on page'
  39. return 1
  40.  
  41. def sms(number, message):
  42. # SEND SMS TO STAFF PHONE LIST
  43. server = smtplib.SMTP('smtp.gmail.com', '587')
  44. server.ehlo()
  45. server.starttls()
  46. server.ehlo()
  47. server.login(username, password)
  48. server.sendmail(username, number, message)
  49. server.quit()
  50.  
  51. def sendemail(to, message):
  52. # SEND EMAIL TO ALL STAFF
  53. server = smtplib.SMTP('smtp.gmail.com', '587')
  54. server.ehlo()
  55. server.starttls()
  56. server.ehlo()
  57. server.login(username, password)
  58. server.sendmail(username, to, message)
  59. server.quit()
  60.  
  61. while True:
  62. # SCRIPT WILL RUN FOR 12 HOURS, AND RESTART VIA CRON
  63. # THIS WILL CHECK EVERY 10 MINUTES UNTIL STRING FOUND, OR
  64. # TWELVE HOURS GOES BY
  65. if findHolyoke(soup(url)) != 1:
  66. break
  67. else:
  68. time.sleep(600)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement