Below is the file 'ttproxy.py' from this revision. You can also download the file.
#!/usr/bin/python import re from urllib import urlencode from urllib2 import urlopen from string import strip, find, join, split import cgi import cgitb import ttparse from sys import exit cgitb.enable() form = cgi.FieldStorage() if form.has_key("ttparse_vcal"): ttparse.parsevcal(form) exit(0) reqfields = [] for z in form.keys(): if find(z, 'ttparse_') == -1: if isinstance(form[z], list): for l in form[z]: reqfields.append((z, l.value)) else: reqfields.append((z, form[z].value)) if form.has_key("ttparse_url"): if isinstance(form["ttparse_url"], list): file = form['ttparse_url'][0].value else: file = form['ttparse_url'].value file = strip(file, "@;\\/%$&? ") else: file = "selectunits.asp" urldata = urlencode(reqfields) url = urlopen("http://www.timetable.uwa.edu.au/Curr/%s" % file, urldata) lines = url.readlines() lines = [strip(l, "\n") for l in lines] print 'Content-type: text/html' print actionre = re.compile('.*FORM METHOD=POST ACTION="(?P<filename>.*)".*') searchre = re.compile('.*http://www.uwa.edu.au/search.php3') leavere = re.compile('.*TopOfPage.*') inhead = 0 donehead = 0 for l in lines: if find(l, "<title>") != -1: l = "<title>iCalendar timetable extractor - %s</title>" % file if not donehead: if not inhead: m = searchre.match(l) if m: inhead = 1 print '</center><p>This is an experimental iCalendar (vCal 2.0) extractor. You should be able to browse to a timetable, then click on the button to grab an iCalendar file of the timetable. These should import with most calendar programs (iCal, Evolution, Thunderbird etc) and some phones too. Please let me know if things don''t seem to be working correctly. This iCalendar extractor is by Matt Johnston <matt at ucc.asn.au>, proxying content from the original <a href="http://www.timetable.uwa.edu.au">www.timetable.uwa.edu.au</a> site. <a href="source/">Source code</a> is available.</p><center>' if find(file, "activities.asp") != -1: print '<form METHOD=POST ACTION="ttparse.py">' for x,y in reqfields: print '<input type=hidden name="ttparse_%s" value="%s">' % (x, y) print "<input type=hidden name=ttparse_url value=%s>" % file print '<input type=submit name=ttparse_vcal value="Get the iCalendar file"></form>' continue else: m = leavere.match(l) if m: inhead = 0 donehead = 1 else: continue m = actionre.match(l) if m: print '<form METHOD=POST ACTION="ttproxy.py"' l = "<input type=hidden name=ttparse_url value=%s>" % m.group("filename") print l