Skip to content

Instantly share code, notes, and snippets.

@brianpartridge
Created December 23, 2012 22:27
Show Gist options
  • Save brianpartridge/4366447 to your computer and use it in GitHub Desktop.
Save brianpartridge/4366447 to your computer and use it in GitHub Desktop.
Pool Schedule
import sys, os
import webbrowser
from bs4 import BeautifulSoup
import urllib
### Config
URL = 'http://www.brooklinema.gov/index.php?option=com_content&view=article&id=208&Itemid=783'
### Functions
def getPage(url):
print "Loading pool website...",
fp = urllib.urlopen(url)
content = fp.read()
print "done"
soup = BeautifulSoup(content)
return soup
def getScheduleURL(soup):
links = soup.find_all("a", text="Monthly Schedule")
if len(links) == 0:
return None
return links[0]['href']
### Logic
print "### Running %s ###" % (os.path.splitext(os.path.split(sys.argv[0])[1])[0])
soup = getPage(URL)
scheduleURL = getScheduleURL(soup)
if not scheduleURL:
scheduleURL = URL
print "Schedule: %s" % scheduleURL
webbrowser.open(scheduleURL)
print "### Done ###"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment