#!/usr/bin/python 

# This script will grab weather info for stuff.mit.edu
# outputs short version (for stuff.mit.edu) in weather_short.html
# outputs long version (linked off of stuff.mit.edu) in weather_full.html

import commands, re

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

weather = commands.getoutput("/afs/athena.mit.edu/project/weather/bin/weather bos")

pattTemp = re.compile("Temp:\s*(.*)")
matchTemp = pattTemp.search(weather)

pattHumidity = re.compile("Humidity:\s*(.*%)")
matchHumidity = pattHumidity.search(weather)

pattWind = re.compile("Wind:\s*(.*)")
matchWind = pattWind.search(weather)

weather_full.write("<HTML><BODY><PRE>\n"+weather+"\n</PRE></BODY></HTML>")
weather_full.close()

if matchTemp is not None and matchHumidity is not None and matchWind is not None:
    weather_short.write(matchTemp.group()+" / "+matchHumidity.group()+" / "+matchWind.group())
weather_short.close()
