-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_table.py
More file actions
26 lines (18 loc) · 876 Bytes
/
create_table.py
File metadata and controls
26 lines (18 loc) · 876 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
import json, sqlite3, os
dirname = os.path.dirname(__file__)
filename = os.path.join(dirname,'seed.json')
with open (filename, 'r', encoding = "utf8") as f:
quotes = json.load(f)
connection = sqlite3.connect('data.db')
cursor = connection.cursor()
# cursor.execute("DROP TABLE anime")
# cursor.execute("DROP TABLE temp")
create_table = "CREATE TABLE IF NOT EXISTS anime (anime text, quote text, author text, color text, logo text, email text)"
cursor.execute(create_table)
query = "INSERT INTO anime VALUES (?, ?, ?, ?, ?, ?)"
for quote in quotes["List"]:
cursor.execute(query,(quote['anime'], quote['quote'], quote['author'], quote['color'], quote['logo'], quote['email']))
temp_table = "CREATE TABLE IF NOT EXISTS temp (anime text, quote text, author text, color text, logo text, email text)"
cursor.execute(temp_table)
connection.commit()
connection.close()