From 897f577706788c75c44aadc2dedc70770a3e0af2 Mon Sep 17 00:00:00 2001 From: Eric Lay Date: Wed, 27 Mar 2024 21:52:53 -0500 Subject: [PATCH] swap if/else for case statement --- app.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app.py b/app.py index 00731d0..d1441ee 100644 --- a/app.py +++ b/app.py @@ -16,18 +16,19 @@ WEBSITE_DIRS = [name for name in os.listdir(ROOT_DIR) if not name.startswith('.' # Site choosing logic def current_website_dir(): session.pop('website_dir', None) - if session['requests'] % 5 == 0: - session['website_dir'] = (os.path.join(ROOT_DIR, 'Marvel')) - elif session['requests'] % 6 == 0: - session['website_dir'] = (os.path.join(ROOT_DIR, 'Escape')) - session.pop('requests', None) - else: - try: - WEBSITE_DIRS.remove(os.path.join(ROOT_DIR, 'Marvel')) - WEBSITE_DIRS.remove(os.path.join(ROOT_DIR, 'Escape')) - except (ValueError, IndexError) as e: - pass - session['website_dir'] = random.choice(WEBSITE_DIRS) + match session['requests']: + case 5: + session['website_dir'] = (os.path.join(ROOT_DIR, 'Marvel')) + case 6: + session['website_dir'] = (os.path.join(ROOT_DIR, 'Escape')) + session.pop('requests', None) + case _: + try: + WEBSITE_DIRS.remove(os.path.join(ROOT_DIR, 'Escape')) + WEBSITE_DIRS.remove(os.path.join(ROOT_DIR, 'Marvel')) + except (ValueError, IndexError) as e: + pass + session['website_dir'] = random.choice(WEBSITE_DIRS) # Make static files available @app.route('/', methods=['GET'])