Update app.py

- moving escape template choosing logic into the website_dir function to better grab assets 
- changed formatting on string for selecting escape template
This commit is contained in:
Eric Lay 2024-03-27 10:02:20 -05:00 committed by GitHub
parent ee1403de23
commit 574c66db5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 9 deletions

18
app.py
View File

@ -13,12 +13,18 @@ unique_requests = set()
# OR change the ROOT_DIR path below :) # OR change the ROOT_DIR path below :)
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
WEBSITE_DIRS = [name for name in os.listdir(ROOT_DIR) if not name.startswith('.') and os.path.isdir(os.path.join(ROOT_DIR, name))] WEBSITE_DIRS = [name for name in os.listdir(ROOT_DIR) if not name.startswith('.') and os.path.isdir(os.path.join(ROOT_DIR, name))]
print(ROOT_DIR)
# Site choosing logic # Site choosing logic
website_dir = None website_dir = None
def current_website_dir(): def current_website_dir():
global website_dir global request_count
website_dir = random.choice(WEBSITE_DIRS) request_count += 1
if request_count % 5 == 0:
global website_dir
website_dir = str(ROOT_DIR+"/Marvel")
else:
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'])
@ -29,13 +35,7 @@ def static_proxy(filename):
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
def index(): def index():
current_website_dir() current_website_dir()
global request_count return send_from_directory(website_dir, 'index.html')
request_count += 1
if request_count % 5 == 0:
return send_from_directory(str(ROOT_DIR+"Marvel/"), 'index.html')
else:
return send_from_directory(website_dir, 'index.html')
if __name__ == "__main__": if __name__ == "__main__":
app.run() app.run()