code before moving database code to its own file.

This commit is contained in:
2026-07-17 14:59:58 -04:00
parent 228cf37eba
commit b573ca05aa
4 changed files with 132 additions and 57 deletions
+50
View File
@@ -0,0 +1,50 @@
import sqlite3
# Stores data locally
CONN = sqlite3.connect("database.db")
CURSOR = CONN.cursor()
class Database():
def __init__():
file_path = Path("database.db")
if file_path.is_file():
self.create_database()
def create_database():
"""Creates a table structured explicitly for Twitch clip properties."""
CURSOR.execute(
"""
CREATE TABLE IF NOT EXISTS clips (
slug TEXT PRIMARY KEY,
date TEXT NOT NULL,
title TEXT NOT NULL,
gamename TEXT NOT NULL,
clip_by TEXT NOT NULL,
view_count INTEGER NOT NULL,
downloaded INTEGER NOT NULL,
uploaded_yt INTEGER NOT NULL
)
"""
)
CURSOR.execute(
"""
CREATE TABLE IF NOT EXISTS vods (
id INTEGER PRIMARY KEY,
date TEXT NOT NULL,
title TEXT NOT NULL,
gamename TEXT NOT NULL,
downloaded INTEGER NOT NULL,
uploaded_yt INTEGER NOT NULL,
chat_upload_yt INTEGER NOT NULL
)
"""
)
CONN.commit()
def close_database():
"""Commit before we close."""
CONN.commit()
CONN.close()