37 lines
899 B
Python
37 lines
899 B
Python
import os
|
|
import sqlite3
|
|
|
|
class VidDatabase():
|
|
|
|
def __init__(self, path):
|
|
self.path = path
|
|
self.is_valid = os.path.isfile(self.path)
|
|
self.con = sqlite3.connect(self.path)
|
|
|
|
def __del__(self):
|
|
self.con.close()
|
|
|
|
def create(self):
|
|
cur = self.con.cursor()
|
|
cur.execute("CREATE TABLE vid (link TEXT NOT NULL, code TEXT NOT NULL);")
|
|
self.con.commit()
|
|
|
|
def select_vid(self, vid):
|
|
cur = self.con.cursor()
|
|
cur.execute("SELECT link, code FROM vid WHERE rowid = ?;", (vid,))
|
|
rows = cur.fetchall()
|
|
video = rows[0] if len(rows) > 0 else None
|
|
self.con.commit()
|
|
return video
|
|
|
|
def insert_vid(self, link, code):
|
|
cur = self.con.cursor()
|
|
cur.execute("INSERT INTO vid (link, code) VALUES (?, ?);", (link, code))
|
|
self.con.commit()
|
|
return cur.lastrowid
|
|
|
|
def delete_vid(self, link):
|
|
cur = self.con.cursor()
|
|
cur.execute("DELETE FROM vid WHERE link = ?;", link)
|
|
self.con.commit()
|