
import os
from flask_app.database import init_db

# Generate new secret key
secret_key = os.urandom(24).encode('hex').strip()
with open('flask_app/secret_key.py', 'w') as key_file:
    key_file.write('secret_key = """' + secret_key + '""".decode("hex")')

# Initialize database
init_db()


import os
from flask_app.database import init_db

# Generate new secret key
key_file_path = 'flask_app/secret_key.py'
if not os.path.isfile(key_file_path):
    secret_key = os.urandom(24).encode('hex').strip()
    with open(key_file_path, 'w') as key_file:
        key_file.write('secret_key = """' + secret_key + '""".decode("hex")')

# Initialize database
init_db()

Check if keyfile exists before generating new key
Check if keyfile exists before generating new key

  
  import os
  from flask_app.database import init_db
  
  # Generate new secret key
+ key_file_path = 'flask_app/secret_key.py'
+ if not os.path.isfile(key_file_path):
- secret_key = os.urandom(24).encode('hex').strip()
+     secret_key = os.urandom(24).encode('hex').strip()
- with open('flask_app/secret_key.py', 'w') as key_file:
+     with open(key_file_path, 'w') as key_file:
-     key_file.write('secret_key = """' + secret_key + '""".decode("hex")')
+         key_file.write('secret_key = """' + secret_key + '""".decode("hex")')
  
  # Initialize database
  init_db()
  
Check if keyfile exists before generating new key
## Code Before:

import os
from flask_app.database import init_db

# Generate new secret key
secret_key = os.urandom(24).encode('hex').strip()
with open('flask_app/secret_key.py', 'w') as key_file:
    key_file.write('secret_key = """' + secret_key + '""".decode("hex")')

# Initialize database
init_db()

## Instruction:
Check if keyfile exists before generating new key
## Code After:

import os
from flask_app.database import init_db

# Generate new secret key
key_file_path = 'flask_app/secret_key.py'
if not os.path.isfile(key_file_path):
    secret_key = os.urandom(24).encode('hex').strip()
    with open(key_file_path, 'w') as key_file:
        key_file.write('secret_key = """' + secret_key + '""".decode("hex")')

# Initialize database
init_db()
