#!/usr/bin/env python

import MySQLdb


db = MySQLdb.connect("localhost", "monitor1", "database112", "temp1")
curs=db.cursor()


try:
    curs.execute ("""INSERT INTO temperature1 
            values(CURRENT_DATE() - INTERVAL 1 DAY, NOW(), 21.7)""")

    db.commit()
    print "Data committed"

except:
    print "Error: the database is being rolled back"
    db.rollback()

curs.execute ("SELECT * FROM temperature1")

print "\nDate     	Time		Temperature"
print "============================================"

for reading in curs.fetchall():
    print str(reading[0])+"	"+str(reading[1])+" 	"+str(reading[2])

db.close()
