Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
style: extract function
Browse files Browse the repository at this point in the history
  • Loading branch information
zdimension committed Jan 28, 2024
1 parent a2dc8c7 commit 7f4ccb7
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions Contents/Code/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,31 @@ def render_template(*args, **kwargs):
database_cache_file = os.path.join(themerr_data_directory, 'database_cache.json')
database_cache_lock = Lock()

secret_file = os.path.join(themerr_data_directory, 'secret.json')

try:
with open(secret_file, 'r') as f:
app.secret_key = json.load(f)['secret']
except Exception:
# create random secret
Log.Info('Creating random secret')
app.secret_key = uuid.uuid4().hex
def create_secret():
"""
Create secret file with random uuid.
Examples
--------
>>> create_secret()
"""
secret_file = os.path.join(themerr_data_directory, 'secret.json')
try:
with open(secret_file, 'w') as f:
json.dump({'secret': app.secret_key}, f)
except Exception as e:
Log.Error('Error saving secret: {}'.format(e))
with open(secret_file, 'r') as f:
app.secret_key = json.load(f)['secret']
except Exception:
# create random secret
Log.Info('Creating random secret')
app.secret_key = uuid.uuid4().hex
try:
with open(secret_file, 'w') as f:
json.dump({'secret': app.secret_key}, f)
except Exception as e:
Log.Error('Error saving secret: {}'.format(e))


create_secret()


responses = {
Expand Down

0 comments on commit 7f4ccb7

Please sign in to comment.