bangla-translator / init_db.py
Chaitanya895's picture
Create init_db.py
879acb3 verified
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()