swap if/else for case statement

This commit is contained in:
Eric Lay 2024-03-27 21:52:53 -05:00
parent 26f2b4f4f2
commit 897f577706
1 changed files with 13 additions and 12 deletions

25
app.py
View File

@ -16,18 +16,19 @@ WEBSITE_DIRS = [name for name in os.listdir(ROOT_DIR) if not name.startswith('.'
# Site choosing logic # Site choosing logic
def current_website_dir(): def current_website_dir():
session.pop('website_dir', None) session.pop('website_dir', None)
if session['requests'] % 5 == 0: match session['requests']:
session['website_dir'] = (os.path.join(ROOT_DIR, 'Marvel')) case 5:
elif session['requests'] % 6 == 0: session['website_dir'] = (os.path.join(ROOT_DIR, 'Marvel'))
session['website_dir'] = (os.path.join(ROOT_DIR, 'Escape')) case 6:
session.pop('requests', None) session['website_dir'] = (os.path.join(ROOT_DIR, 'Escape'))
else: session.pop('requests', None)
try: case _:
WEBSITE_DIRS.remove(os.path.join(ROOT_DIR, 'Marvel')) try:
WEBSITE_DIRS.remove(os.path.join(ROOT_DIR, 'Escape')) WEBSITE_DIRS.remove(os.path.join(ROOT_DIR, 'Escape'))
except (ValueError, IndexError) as e: WEBSITE_DIRS.remove(os.path.join(ROOT_DIR, 'Marvel'))
pass except (ValueError, IndexError) as e:
session['website_dir'] = random.choice(WEBSITE_DIRS) pass
session['website_dir'] = random.choice(WEBSITE_DIRS)
# Make static files available # Make static files available
@app.route('/<path:filename>', methods=['GET']) @app.route('/<path:filename>', methods=['GET'])