Created
December 23, 2012 22:27
-
-
Save brianpartridge/4366447 to your computer and use it in GitHub Desktop.
Pool Schedule
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 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