Update app.py
Total rework to requests count using Flask session
This commit is contained in:
parent
888b082eb6
commit
279e492193
22
app.py
22
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)
|
||||
|
|
Loading…
Reference in New Issue