-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpopulation.py
33 lines (30 loc) · 936 Bytes
/
population.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
#this can fill db with data from local file
#or restore the data in the database in case someone messes up the db
import csv
from ComedianIdentifier.dbmanager import DatabaseManager
name = 'textfiles/Final CSV - Sheet1.csv'
#parse data from csv
def populate(filename):
data = []
with open(filename) as file:
reader = csv.reader(file, delimiter=',')
line = 0
for row in reader:
if line != 0: #excluding column title
data.append(row)
line += 1
return data
if __name__ == '__main__':
temp_data = populate(name)
db_manager = DatabaseManager()
for i in temp_data:
command = f'''INSERT INTO JOKES VALUES (
"{i[0]}",
"{i[3].replace('"', "'")}",
{i[1]},
{i[2]}
)
'''
db_manager.execute(command)
db_manager.commit()
db_manager.close()