Skip to content

Instantly share code, notes, and snippets.

@joshuagruenstein
Created January 22, 2016 02:16
Show Gist options
  • Save joshuagruenstein/2e1035bc5efb92618208 to your computer and use it in GitHub Desktop.
Save joshuagruenstein/2e1035bc5efb92618208 to your computer and use it in GitHub Desktop.
A python notifier for SAT cancellations.
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