-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfavourite1.py
24 lines (17 loc) · 868 Bytes
/
favourite1.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
import csv
import sqlite3
# way to create a empty file
open("shows.db","w").close() # -> opening and closing and file
db = sqlite3.connect("shows.db") # connecting sqlite3 to the database
c = db.cursor()
# db.execute("CREATE TABLE IF NOT EXISTS shows (id INTEGER,title TEXT,PRIMARY KEY(id))")
# db.execute("CREATE TABLE IF NOT EXISTS genres (show_id INTEGER,genre TEXT,FOREIGN KEY(show_id) REFERENCES shows(id)")
# db.execute("DROP TABLE shows")
# db.execute("DROP TABLE genres")
c.execute("CREATE TABLE shows (id INTEGER ,title STRING,PRIMARY KEY(id))")
c.execute("CREATE TABLE genres (id INTEGER,genre TEXT,FOREIGN KEY(id) REFERENCES shows(id))")
with open("top_movies.csv","r") as file:
reader = csv.DictReader(file)
for row in reader:
title = row["movie"].strip().upper()
c.executemany("INSERT INTO shows (title) VALUES(?)",[title,])