Skip to content

Instantly share code, notes, and snippets.

@dgrant
Last active December 18, 2015 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgrant/5727206 to your computer and use it in GitHub Desktop.
Save dgrant/5727206 to your computer and use it in GitHub Desktop.
Checks swimming lessons availability with the City of Vancouver.
#!/usr/bin/env python2
"""
Search for swimming lessons on the Vancouver Aquatic Services web page
that match certain criteria.
"""
import urllib2
import json
#WP=Lord Byng
#VC=Vancouver Aquatic Centre
#KL=Killarney
SITES = ["KL"]
URL = "http://vancouver.ca/SafariActivityList_wa/SafariActivityListEnc.cfm" +\
"?fmt=j&site=%s&agegroup=1&category=51"
def main():
""" Main function """
lessons = []
for site in SITES:
json_data = urllib2.urlopen(URL % site).read()
print URL % site
lessons += json.loads(json_data)
print lessons
lessons = [lesson
for lesson in lessons
# Type of swimming lesson
if all([
lesson['activityname'].lower().find("sunfish") != -1,
# Day of week
# lesson['weekdays_short'].find("Th") != -1,
# Only classes with open spots
int(lesson['numberopen']) != 0,
# Only 2011
# lesson['startdate'].find('2011') != -1,
# Only non-closed registration
lesson['status'].find('Closed') == -1,
])]
for lesson in lessons:
print lesson['activityname'], \
lesson['facilityname'], \
lesson['status'], \
lesson['startdate'], \
lesson['starttime'], \
lesson['numberopen'], '/', lesson['enrollmax']
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment