update Database to use default in init

This commit is contained in:
2026-07-29 03:03:29 +00:00
parent 500fe87614
commit b6d9b56848
7 changed files with 107 additions and 84 deletions
+17 -8
View File
@@ -8,9 +8,9 @@ class Database:
def __init__(self, db_path: str = "database.db"):
self.columns = "id, title, created_at, view_count, duration, url, thumbnail_url, game_id, game_name, stream_id, creator_name, clip_is, downloaded, uploaded_yt, uploaded_yt_chats, uploaded_yt_shorts"
file_exists = self.db_path.is_file()
file_exists = Path(db_path).is_file()
self.conn = sqlite3.connect("database.db")
self.conn = sqlite3.connect(db_path)
self.cursor = self.conn.cursor()
if not file_exists:
@@ -54,10 +54,10 @@ class Database:
self.conn.commit()
self.conn.close()
def __mark_as(self, record_id: str, set_sql: str):
def __mark_as(self, record_id: str, set_row: str, mark: str = "1" ):
self.cursor.execute(
f"UPDATE twitch_videos SET {set_sql} = 1 WHERE id = ?",
(record_id,))
f"UPDATE twitch_videos SET {set_row} = ? WHERE id = ?",
(mark, record_id))
self.conn.commit()
def mark_as_uploaded_shorts(self, record_id: str):
@@ -76,9 +76,13 @@ class Database:
"""Flags a specific row record to downloaded (1)."""
self.__mark_as(record_id, "downloaded")
def __get_unuploaded(self, set_sql: str) -> list[Any]:
def unmark_as_download(self, record_id: str):
"""Flags a specific row record to downloaded (0)."""
self.__mark_as(record_id, "downloaded", "0")
def __get_unuploaded(self, set_row: str) -> list[Any]:
"""Retrieve all rows that were download but not uploaded"""
self.cursor.execute(f"SELECT {self.columns} FROM twitch_videos WHERE downloaded = 1 AND {set_sql} = 0")
self.cursor.execute(f"SELECT {self.columns} FROM twitch_videos WHERE downloaded = 1 AND {set_row} = 0")
return self.cursor.fetchall()
def get_unuploaded_shorts(self) -> list[Any]:
@@ -98,6 +102,11 @@ class Database:
self.cursor.execute(f"SELECT {self.columns} FROM twitch_videos WHERE downloaded = 0")
return self.cursor.fetchall()
def get_clips(self) -> list[Any]:
"""Retrieves all rows that are clip_is"""
self.cursor.execute(f"SELECT {self.columns} FROM twitch_videos WHERE clip_is = 1")
return self.cursor.fetchall()
def insert_video_record(
self, id: str, title: str, created_at: str, view_count: int, duration: str,
url: str, thumbnail_url: str, game_id: int, game_name: str, stream_id: str,
@@ -127,5 +136,5 @@ class Database:
self.conn.commit()
except Exception as e:
# Prevent silent failures if the database connection drops
print(f"Database insertion failed: {e}")
print(f"Database insertion failed: {e}")
self.conn.rollback()