From 279e492193edd0d5791ee8e0b1fc77385a8892c2 Mon Sep 17 00:00:00 2001 From: Eric Lay Date: Wed, 27 Mar 2024 18:17:11 -0500 Subject: [PATCH] Update app.py Total rework to requests count using Flask session --- app.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app.py b/app.py index 149b384..e79616a 100644 --- a/app.py +++ b/app.py @@ -1,13 +1,12 @@ import os -import uuid import random -from flask import Flask, send_from_directory, request +from flask import Flask, send_from_directory, session app = Flask(__name__) -# Implement count to load specific page on Nth -request_count = 0 -unique_requests = set() +# Implement count to load specific page on Nth load +# Using session['requests'] +app.secret_key = '420-69' # Script must run from root dir containing all websites dirs # OR change the ROOT_DIR path below :) @@ -17,13 +16,12 @@ WEBSITE_DIRS = [name for name in os.listdir(ROOT_DIR) if not name.startswith('.' # Site choosing logic website_dir = None def current_website_dir(): - global request_count - request_count += 1 - if request_count % 5 == 0: + if session['requests'] % 5 == 0: global website_dir website_dir = str(ROOT_DIR+"/Marvel") - elif request_count % 6 == 0: + elif session['requests'] % 6 == 0: website_dir = str(ROOT_DIR+"/Escape") + session.pop('requests', None) else: global WEBSITE_DIRS try: @@ -41,8 +39,12 @@ def static_proxy(filename): # Serve site index.html @app.route('/', methods=['GET']) def index(): + if 'requests' in session: + session['requests'] += 1 + else: + session['requests'] = 1 current_website_dir() return send_from_directory(website_dir, 'index.html') if __name__ == "__main__": - app.run() + app.run(debug=True)