update to the process_uploads upload.py and new database table called data
This commit is contained in:
1 parent
afe6490d20
commit
2773200a94
17 files changed
+245
-70
No files matched your search
@@ -7,6 +7,7 @@ from typing import Any
|
||||
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"
|
||||
self.data = "id, name, date_shorts, date_videos, date_videos_chat"
|
||||
|
||||
file_exists = Path(db_path).is_file()
|
||||
|
||||
@@ -45,6 +46,16 @@ class Database:
|
||||
uploaded_yt_shorts BOOLEAN NOT NULL DEFAULT 0
|
||||
)
|
||||
""")
|
||||
|
||||
self.cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS data (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
date_shorts TEXT NOT NULL,
|
||||
date_videos TEXT NOT NULL,
|
||||
date_videos_chat TEXT NOT NULL
|
||||
)
|
||||
""")
|
||||
|
||||
self.conn.commit()
|
||||
|
||||
@@ -167,3 +178,55 @@ class Database:
|
||||
# Prevent silent failures if the database connection drops
|
||||
print(f"❌ Database insertion failed: {e}")
|
||||
self.conn.rollback()
|
||||
|
||||
def __update_date(self, record_id: str, set_row: str, date: str):
|
||||
"""Updates the Datetime for timezone fix"""
|
||||
self.cursor.execute(
|
||||
f"UPDATE data SET {set_row} = ? WHERE id = ?",
|
||||
(date, record_id))
|
||||
self.conn.commit()
|
||||
|
||||
def update_date_shorts(self, record_id: str, date_shorts: str):
|
||||
self.__update_date(record_id, "date_shorts", date_shorts)
|
||||
|
||||
def get_data(self) -> list[Any]:
|
||||
self.cursor.execute(f"SELECT {self.data} FROM data")
|
||||
return self.cursor.fetchall()
|
||||
|
||||
def insert_data_record(self, name: str, date_shorts: str, date_videos: str, date_videos_chat: str):
|
||||
try:
|
||||
dt_obj = datetime.strptime(date_shorts, "%Y-%m-%dT%H:%M:%SZ")
|
||||
clean_date_shorts = dt_obj.strftime("%Y-%m-%d %H:%M:%S")
|
||||
except (ValueError, TypeError):
|
||||
clean_date_shorts = date_shorts
|
||||
|
||||
try:
|
||||
dt_obj = datetime.strptime(date_videos, "%Y-%m-%dT%H:%M:%SZ")
|
||||
clean_date_videos = dt_obj.strftime("%Y-%m-%d %H:%M:%S")
|
||||
except (ValueError, TypeError):
|
||||
clean_date_videos = date_videos
|
||||
|
||||
try:
|
||||
dt_obj = datetime.strptime(date_videos_chat, "%Y-%m-%dT%H:%M:%SZ")
|
||||
clean_date_videos_chat = dt_obj.strftime("%Y-%m-%d %H:%M:%S")
|
||||
except (ValueError, TypeError):
|
||||
clean_date_videos_chat = date_videos_chat
|
||||
|
||||
# Explicitly defining columns removes the security risk and column-count bug
|
||||
query = """
|
||||
INSERT INTO data (
|
||||
name, date_shorts, date_videos, date_videos_chat
|
||||
) VALUES (?, ?, ?, ?)
|
||||
"""
|
||||
|
||||
values = (
|
||||
name, clean_date_shorts, clean_date_videos, clean_date_videos_chat
|
||||
)
|
||||
|
||||
try:
|
||||
self.cursor.execute(query, values)
|
||||
self.conn.commit()
|
||||
except Exception as e:
|
||||
# Prevent silent failures if the database connection drops
|
||||
print(f"❌ Database insertion failed: {e}")
|
||||
self.conn.rollback()
|
||||
Reference in new issue
Block a user