-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_sqlite.py
69 lines (60 loc) · 2.03 KB
/
main_sqlite.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import sqlite3
con = sqlite3.connect("youtube.db")
cursor = con.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS videos (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
time TEXT NOT NULL
)
''')
def list_all_videos():
cursor.execute("select * FROM videos")
print("\n")
print("*"*70)
data = cursor.fetchall()
for index, name , time in data:
print(f"{index}. Name: {name}, Duration: {time}")
print("*"*70)
def add_video(name, time):
cursor.execute("INSERT INTO videos (name,time) VALUES (?, ?)" , (name, time))
con.commit()
def update_video(video_id, name, time):
list_all_videos()
cursor.execute("UPDATE videos SET name = ?, time = ? WHERE id = ?", (name , time, video_id))
con.commit()
def delete_video(video_id):
list_all_videos()
cursor.execute("DELETE FROM videos WHERE id = ?", (video_id,))
con.commit()
def main():
while True:
print("\nYoutube Manager | Choose an option")
print("1. List all youtube videos")
print("2. Add a youtube video")
print("3. Update a youtube video")
print("4. Delete a youtube video")
print("5. Exit the program")
choice = input("Enter your choice\n")
match choice:
case '1':
list_all_videos()
case '2':
name = input("Enter the video name\n")
time = input("Enter the video time\n")
add_video(name , time)
case '3':
video_id = input("Enter video id to update\n")
name = input("Enter the video name\n")
time = input("Enter the video time\n")
update_video(video_id, name, time)
case '4':
video_id = input("Enter video id to delete\n")
delete_video(video_id)
case '5':
break
case _:
print("Invalid choice please enter a valid choice")
con.close()
if __name__ == "__main__":
main()