Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
DB path and file checks
  • Loading branch information
LucifersCircle committed Dec 7, 2024
1 parent eef1d6f commit b478a24
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@

# Function to initialize the database if it doesn't exist
def initialize_db():
if os.path.exists(DB_FILE) and not os.path.isfile(DB_FILE):
print(f"Error: {DB_FILE} exists but is not a file. Removing it.")
os.rmdir(DB_FILE) # Remove the directory

if not os.path.exists(DB_FILE):
conn = sqlite3.connect(DB_FILE)
conn.execute('''
CREATE TABLE IF NOT EXISTS keys (
id INTEGER PRIMARY KEY AUTOINCREMENT,
encrypted_key BLOB NOT NULL
)
''')
conn.commit()
conn.close()
print("Database initialized")
try:
conn = sqlite3.connect(DB_FILE)
conn.execute('''
CREATE TABLE IF NOT EXISTS keys (
id INTEGER PRIMARY KEY AUTOINCREMENT,
encrypted_key BLOB NOT NULL
)
''')
conn.commit()
conn.close()
print("Database initialized")
except Exception as e:
print(f"Error initializing database: {e}")

# Initialize database on startup
initialize_db()
Expand Down

0 comments on commit b478a24

Please sign in to comment.