-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
33 lines (29 loc) · 951 Bytes
/
db.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
import sqlite3
async def set_data(arr):
database = sqlite3.connect("lectures.db")
sql = database.cursor()
sql.execute("""CREATE TABLE IF NOT EXISTS lectures (
url TEXT,
time BIGINT,
UNIQUE(url)
)""")
database.commit()
for i in arr:
sql.execute("""INSERT OR IGNORE into lectures VALUES(?,?)""",(i[0],i[1]))
database.commit()
sql.close()
database.close()
async def get_last_record():
database = database = sqlite3.connect("lectures.db")
sql = database.cursor()
result = sql.execute("""SELECT * FROM lectures WHERE TIME = (SELECT MIN(TIME) from lectures)""").fetchone()
sql.close()
database.close()
return result
async def delete_url(url):
database = database = sqlite3.connect("lectures.db")
sql = database.cursor()
sql.execute("""DELETE FROM lectures WHERE url = ? """,(url,))
database.commit()
sql.close()
database.close()