-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
32 lines (27 loc) · 935 Bytes
/
db.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
import sqlite3
def drop_table():
with sqlite3.connect('greenhouse.db') as connection:
c = connection.cursor()
c.execute('DROP TABLE IF EXISTS greenhouse')
return True
def create_db():
with sqlite3.connect('greenhouse.db') as connection:
c = connection.cursor()
c.execute('CREATE TABLE greenhouse (time REAL, temp REAL)')
return True
def seed():
#open the database
with sqlite3.connect('greenhouse.db') as connection:
c = connection.cursor()
#open the datafile
with open(file_name, 'r') as data:
#interate through the datafile
for value in data:
value.replace('\n', '')
array = value.split(',')
values = [array[0], array[1]]
c.execute('INSERT INTO greenhouse VALUES(?, ?)', values)
if __name__ == '__main__':
drop_table()
create_db()
seed('data.dat')