Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib, requests
- from BeautifulSoup import BeautifulSoup as bs
- import time
- header = {"User-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36"}
- url = 'http://www.westernmassnews.com/category/211531/storm-closings'
- lookFor = 'Holyoke Schools'
- username = '***@gmail.com'
- password = '******'
- eMail = 'staff@***.com'
- numbers = ['413*******@tmomail.net']
- def soup(url):
- # REQUEST SITE, RETURN PARSED HTML
- site = requests.get(url, headers = header).text
- soup = bs(site)
- return soup
- def findHolyoke(soup):
- # LOOK FOR STRING IN 'all_closings' DIV. IF FOUND, FIRE
- # OFF EMAIL AND SMS
- try:
- findings = soup.find('div', id = 'all_closings').text
- except AttributeError:
- print "Didn't find anything!"
- return 0
- if lookFor in findings:
- count = 1
- for num in numbers:
- print 'SMS # ' + str(count) + ' sent to ' + str(num)
- sms(num, 'School is closed, or has a delay today due to inclement weather. Please check local news for more info.')
- count += 1
- print 'eMail Sent to staff@****.com!'
- sendemail(eMail, 'School is closed, or has a delay today due to inclement weather. Please check local news for more info. ')
- else:
- # print 'Holyoke Schools not found on page'
- return 1
- def sms(number, message):
- # SEND SMS TO STAFF PHONE LIST
- server = smtplib.SMTP('smtp.gmail.com', '587')
- server.ehlo()
- server.starttls()
- server.ehlo()
- server.login(username, password)
- server.sendmail(username, number, message)
- server.quit()
- def sendemail(to, message):
- # SEND EMAIL TO ALL STAFF
- server = smtplib.SMTP('smtp.gmail.com', '587')
- server.ehlo()
- server.starttls()
- server.ehlo()
- server.login(username, password)
- server.sendmail(username, to, message)
- server.quit()
- while True:
- # SCRIPT WILL RUN FOR 12 HOURS, AND RESTART VIA CRON
- # THIS WILL CHECK EVERY 10 MINUTES UNTIL STRING FOUND, OR
- # TWELVE HOURS GOES BY
- if findHolyoke(soup(url)) != 1:
- break
- else:
- time.sleep(600)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement