-
Notifications
You must be signed in to change notification settings - Fork 2
/
import.py
33 lines (28 loc) · 942 Bytes
/
import.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
from datetime import datetime
import sqlite3
def inverse_format_datetime(orig):
dt = datetime.strptime(orig, "%M-%H-%d-%m-%y");
return dt.strftime("%Y-%m-%d %H:%M");
def main():
db = sqlite3.connect("rawdata.sqlite")
db.execute(
'''CREATE TABLE IF NOT EXISTS rawdata
(aika TEXT, -- Vaatii tietyn formaatin
lampo INTEGER, -- oispa kaljaa
ovi INTEGER,
valo INTEGER);''')
c = db.cursor()
data = []
with open('rawdata.csv', 'r') as f:
f.readline() # Discard first line
for line in f:
row = line.split(',')
c.execute('''INSERT INTO rawdata VALUES
(?, ?, ?, ?)''',
(inverse_format_datetime(row[0]),
row[1],
row[2],
row[3]))
db.commit()
if __name__ == '__main__':
main()