| import sqlite3 | |
| import os | |
| from datetime import datetime | |
| DB_PATH = os.path.join(os.path.dirname(__file__), 'history.db') | |
| def init_db(): | |
| conn = sqlite3.connect(DB_PATH) | |
| cursor = conn.cursor() | |
| cursor.execute(''' | |
| CREATE TABLE IF NOT EXISTS compression_history ( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| original_filename TEXT NOT NULL, | |
| target_size_mb REAL NOT NULL, | |
| final_size_mb REAL NOT NULL, | |
| duration_sec REAL NOT NULL, | |
| resolution TEXT, | |
| fps INTEGER, | |
| timestamp DATETIME DEFAULT CURRENT_TIMESTAMP | |
| ) | |
| ''') | |
| conn.commit() | |
| conn.close() | |
| def insert_record(original_filename, target_size_mb, final_size_mb, duration_sec, resolution, fps): | |
| conn = sqlite3.connect(DB_PATH) | |
| cursor = conn.cursor() | |
| cursor.execute(''' | |
| INSERT INTO compression_history | |
| (original_filename, target_size_mb, final_size_mb, duration_sec, resolution, fps, timestamp) | |
| VALUES (?, ?, ?, ?, ?, ?, ?) | |
| ''', (original_filename, target_size_mb, final_size_mb, duration_sec, resolution, fps, datetime.now())) | |
| conn.commit() | |
| conn.close() | |
| def get_records(): | |
| conn = sqlite3.connect(DB_PATH) | |
| cursor = conn.cursor() | |
| cursor.execute('SELECT * FROM compression_history ORDER BY timestamp DESC') | |
| records = cursor.fetchall() | |
| conn.close() | |
| return records | |