-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadRecipiesFromCSV.py
More file actions
39 lines (31 loc) · 989 Bytes
/
loadRecipiesFromCSV.py
File metadata and controls
39 lines (31 loc) · 989 Bytes
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
import sqlite3
import csv
from database import database
def get_connection(name):
conn = sqlite3.connect(name)
conn.row_factory = sqlite3.Row
return conn
conn = get_connection('fridge.db')
cursor = conn.cursor()
database.execute_sql_script('db_init_recipies.sql', conn.cursor())
with open('static\\csv\\recipes.csv','r') as f:
for line in f:
reader = csv.reader(f)
data = next(reader)
query = 'insert into recipies values ({0})'
query = query.format(','.join('?' * (len(data)+1)))
cursor = conn.cursor()
final_data = []
final_data.append(None)
for item in data:
final_data.append(item)
cursor.execute(query, final_data )
for data in reader:
final_data = []
final_data.append(None)
for item in data:
final_data.append(item)
cursor.execute(query, final_data)
conn.commit()
conn.rollback()
conn.close()