#! /afs/sipb.mit.edu/project/python/.build.sun/sun4x_58/bin/python 

# This script will grab shuttletrack info for stuff.mit.edu
# puts table of shuttletrack info in shuttletrack.html

import commands, re

#if we had tickets, this would work
#instead, we will write locally
#shuttletrack=open('/afs/sipb/project/www/root/processed/shuttletrack.html', 'w')
shuttletrack=open('/var/www/processed/shuttletrack.html', 'w')

raw_data = commands.getoutput("/afs/athena.mit.edu/project/gnu/bin/wget -q http://shuttletrack.mit.edu/simple.php -O -")

if raw_data:

	pattern = re.compile("\d:(.*?):\d*:\d*:\d*:(\d*?):(\d*?):(\d*?):(.*?):(.*?):\d*:\d*:\d*:\d*:\d*:\d*:\d*")

	parsed_data = pattern.findall(raw_data) 

	#shuttletrack.write("Route | Time | Current stop | Next stop<br>")

	for i in range(len(parsed_data)):
		#i've commented out the last field ("next stop") for now to save real estate and also because it doesn't seem intuitive on the page
        	shuttletrack.write("<nobr>&nbsp&nbsp %s | %s:%s:%s | %s<!-- | %s --></nobr><br>" % (parsed_data[i]))

else:
	shuttletrack.write("<i>&nbsp&nbsp no shuttles currently running</i><br>")

shuttletrack.close()
