Spaces:
Sleeping
Sleeping
File size: 1,088 Bytes
879acb3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import sqlite3
import os
# Define database path
DB_PATH = "/app/translations.db"
def initialize_database():
"""
Initialize the SQLite database and create the translations table if it doesn't exist.
"""
try:
# Ensure the directory for the database exists
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
with sqlite3.connect(DB_PATH) as conn:
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS translations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
url TEXT,
extracted_text TEXT,
translated_text TEXT,
translated_sentences TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
)
""")
conn.commit()
print(f"Database initialized successfully at {DB_PATH}")
except sqlite3.Error as e:
print(f"Error initializing database: {str(e)}")
raise
if __name__ == "__main__":
initialize_database() |