-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdatabase.py
55 lines (47 loc) · 1.65 KB
/
database.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
###########################################################################
# Sint Wind PI
# Copyright 2012 by Tonino Tarsi <[email protected]>
#
# Please refer to the LICENSE file for conditions
# Visit http://www.vololiberomontecucco.it
#
##########################################################################
import serial
import time
import sys
import struct
import ConfigParser
import sqlite3
# Open database commection and cursor
def resetDB(filename='db/swpi.s3db',delete_all=False):
conn = sqlite3.connect(filename,200)
dbCursor = conn.cursor()
if delete_all :
dbCursor.execute("delete from SMS")
dbCursor.execute("delete from CALL")
dbCursor.execute("delete from METEO")
conn.commit()
print "DB Resetted "
if __name__ == '__main__':
resetDB(delete_all=True)
exit(0)
conn = sqlite3.connect('db/swpi.s3db',200)
dbCursor = conn.cursor()
dbCursor.execute("SELECT * FROM METEO where datetime(TIMESTAMP_LOCAL) > datetime('now','-1 day') order by rowid asc limit 1")
data = dbCursor.fetchall()
print "rain_rate_24h" , data
if ( len(data) == 1):
therain = (data[0][9])
rain_rate_24h = therain
print rain_rate_24h
else : print " nodara"
dbCursor.execute("SELECT * FROM METEO where datetime(TIMESTAMP_LOCAL) > datetime('now','-1 hour') order by rowid asc limit 1")
data = dbCursor.fetchall()
print "rain_rate_1h" , data
if ( len(data) == 1):
therain = (data[0][9])
rain_rate_1h = therain
print rain_rate_1h
else : print " nodara"
if conn:
conn.close()