-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmigrate.py
44 lines (29 loc) · 1.28 KB
/
migrate.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
import os
import sqlite3
import sensor
__author__ = 'pspychalski'
db_connection = None
def main():
sensor_handler = sensor.sensor()
global db_connection
db_connection = sensor_handler.get_db_connection()
c = db_connection.cursor()
c.execute('DROP TABLE IF EXISTS sensor_values')
c.execute('CREATE TABLE IF NOT EXISTS sensor_values(`Date` integer, `Sensor` integer, `Value` real)')
source_connection = sqlite3.connect(os.path.dirname(os.path.realpath(__file__)) + '/data.db')
cursor_source = source_connection.cursor()
result = cursor_source.execute('SELECT * FROM readouts_external')
for row in result:
sensor_handler.insert_no_commit(row[0], 0, row[1]) # Temperature
sensor_handler.insert_no_commit(row[0], 1, row[2]) # Humidity
# print row
result = cursor_source.execute('SELECT * FROM external_data')
for row in result:
sensor_handler.insert_no_commit(row[0], 2, row[1]) # Real Pressure
sensor_handler.insert_no_commit(row[0], 4, row[2]) # Wind Speed
sensor_handler.insert_no_commit(row[0], 5, row[3]) # Wind direction
# print row
c.execute('CREATE INDEX IF NOT EXISTS SENSOR_A ON sensor_values(`Date`, `Sensor`)')
db_connection.commit()
if __name__ == "__main__":
main()