
import MySQLdb

def index (req, an_arg='defaulit'):
	req.content_type = 'text/csvi'
	req.headers_out.add("Content-Disposition", "attachment; filename=wunderground.csv")
	conn = MySQLdb.connect(host = "localhost",
                        user = "glacsweb-ro",
                        passwd = "iceland",
                        db = "iceland")
	cursor = conn.cursor ()
	cursor.execute("SELECT name, timestamp, temperature, humidity, wind_direction, wind_speed, pressure, dewpoint, visibility FROM `weather`, weather_locations WHERE weather_locations.id = weather.location_id")
	rows = cursor.fetchall()
	s = "Location, timestamp, temperature, humidity, wind direction, wind speed, pressue, dewpoint, visibility\n"
	for row in rows:
		s += "%s,%s,%d,%d,%d,%d,%d,%s,%s\n" % (row[0],str(row[1]), row[2], row[3],row[4],row[5],row[6],row[7], row[8]) 
	cursor.close()
	conn.close()
	return s
