-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempLog.py
More file actions
40 lines (32 loc) · 1.05 KB
/
tempLog.py
File metadata and controls
40 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
import MySQLdb
import Home_Automation
def insertTemp(temp,curs,db):
with db:
curs.execute ("INSERT INTO temps values(CURRENT_DATE(),CURTIME(),"+str(temp)+")")
db.commit()
##print temp,"committed"
def printData():
curs=db.cursor()
curs.execute ("SELECT * FROM temps")
print "\nDate Time Temperature"
print "======================================="
num = 0
for reading in curs.fetchall():
print str(reading[0])+" "+str(reading[1])+" "+str(reading[2])
num +=1
print "Number of enteries printed", num
if __name__ == '__main__':
db = MySQLdb.connect("localhost", "mtangy", "*password**", "roomTemps")
curs=db.cursor()
iter = 0
while True:
temp = 0.0;
temp = Home_Automation.getCurrentTemp()
insertTemp(temp,curs,db)
t = open('/usr/local/bin/temp.txt', 'r')
utemp = int(t.read().strip())
t.close()
if utemp > temp:
Home_Automation.turnACoff()
time.sleep(1000)