-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathytmanager_with_sqllite.py
More file actions
64 lines (53 loc) · 1.76 KB
/
ytmanager_with_sqllite.py
File metadata and controls
64 lines (53 loc) · 1.76 KB
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
import sqlite3
conn = sqlite3.connect('youtube_videos.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS videos (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
time TEXT NOT NULL
)
''')
def list_videos():
cursor.execute("SELECT * FROM videos")
for row in cursor.fetchall():
print(row)
def add_video(name, time):
cursor.execute("INSERT INTO videos (name, time) VALUES (?, ?)", (name, time))
conn.commit()
def update_video(video_id, new_name, new_time):
cursor.execute("UPDATE videos SET name = ?, time = ? WHERE id = ?", (new_name, new_time, video_id))
conn.commit()
def delete_video(video_id):
cursor.execute("DELETE FROM videos where id = ?", (video_id,))
conn.commit()
def main():
while True:
print("\n Youtube manager app with DB")
print("1. List Videos")
print("2. Add Videos")
print("3. Update Videos")
print("4. Delete Videos")
print("5. exit app")
choice = input("Enter your choice: ")
if choice == '1':
list_videos()
elif choice == '2':
name = input("Enter the video name: ")
time = input("Enter the video time: ")
add_video(name, time)
elif choice == '3':
video_id = input("Enter video ID to update: ")
name = input("Enter the video name: ")
time = input("Enter the video time: ")
update_video(video_id, name, time)
elif choice == '4':
video_id = input("Enter video ID to delete: ")
delete_video(video_id)
elif choice == '5':
break
else:
print("Invalid Choice ")
conn.close()
if __name__ == "__main__":
main()