Created
January 22, 2016 02:16
-
-
Save joshuagruenstein/2e1035bc5efb92618208 to your computer and use it in GitHub Desktop.
A python notifier for SAT cancellations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from BeautifulSoup import BeautifulSoup | |
import time | |
from Foundation import NSUserNotification | |
from Foundation import NSUserNotificationCenter | |
from Foundation import NSUserNotificationDefaultSoundName | |
from optparse import OptionParser | |
def notify(school): | |
parser = OptionParser(usage='%prog -t TITLE -m MESSAGE') | |
parser.add_option('-t', '--title', action='store', default='New SAT Cancellation') | |
parser.add_option('-m', '--message', action='store', default=school) | |
parser.add_option('--sound', action='store_false', default=True, dest='sound') | |
options, args = parser.parse_args() | |
notification = NSUserNotification.alloc().init() | |
notification.setTitle_(options.title) | |
notification.setInformativeText_(options.message) | |
if options.sound: | |
notification.setSoundName_(NSUserNotificationDefaultSoundName) | |
center = NSUserNotificationCenter.defaultUserNotificationCenter() | |
center.deliverNotification_(notification) | |
schoolSet = set() | |
while True: | |
html = requests.get('https://sat.collegeboard.org/register/sat-test-center-closings').content | |
soup = BeautifulSoup(html) | |
schools = soup.find('div', attrs={'id': 'closedNY'}).findAll("tr") | |
for school in schools[1:]: | |
curSchool = str(school).split('\n')[2][4:-5].title() | |
if not (curSchool in schoolSet): | |
schoolSet.add(curSchool) | |
notify(curSchool) | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment