-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
67 lines (47 loc) · 1.56 KB
/
database.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
import sqlite3
def init_db(db_name):
'''Initialize db. Will create necessary tables if don't exist'''
# home_directory = os.path.expanduser('~')
# db_path = os.path.join(db_path.replace('~', home_directory),db_name)
con = sqlite3.connect(db_name)
con.execute('CREATE TABLE IF NOT EXISTS videos(VideoID)')
con.execute('CREATE TABLE IF NOT EXISTS uploads(UploadID)')
return con
def insert_channel_detail(con, upload_id):
'''Create channeldetails into db'''
with con:
sql = ''' INSERT INTO uploads(UploadID)
VALUES(?) '''
value = (upload_id,)
cur = con.cursor()
cur.execute(sql, value)
con.commit()
return cur.lastrowid
def insert_video_id(con, video_id):
'''Create channeldetails into db'''
with con:
sql = ''' INSERT INTO videos(VideoID)
VALUES(?) '''
value = (video_id,)
cur = con.cursor()
cur.execute(sql, value)
con.commit()
return cur.lastrowid
def get_video_ids(con):
'''Pull all video id's that have been used'''
with con:
sql = '''SELECT VideoID FROM videos'''
cur = con.cursor()
cur.execute(sql)
rows = cur.fetchall()
videos = [i[0] for i in rows]
return videos
def get_uploads_ids(con):
'''Pull all video id's that have been used'''
with con:
sql = '''SELECT UploadID FROM uploads'''
cur = con.cursor()
cur.execute(sql)
rows = cur.fetchall()
uploads = [i[0] for i in rows]
return uploads