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 os
|
||||||
import uuid
|
|
||||||
import random
|
import random
|
||||||
from flask import Flask, send_from_directory, request
|
from flask import Flask, send_from_directory, session
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
# Implement count to load specific page on Nth
|
# Implement count to load specific page on Nth load
|
||||||
request_count = 0
|
# Using session['requests']
|
||||||
unique_requests = set()
|
app.secret_key = '420-69'
|
||||||
|
|
||||||
# Script must run from root dir containing all websites dirs
|
# Script must run from root dir containing all websites dirs
|
||||||
# OR change the ROOT_DIR path below :)
|
# 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
|
# Site choosing logic
|
||||||
website_dir = None
|
website_dir = None
|
||||||
def current_website_dir():
|
def current_website_dir():
|
||||||
global request_count
|
if session['requests'] % 5 == 0:
|
||||||
request_count += 1
|
|
||||||
if request_count % 5 == 0:
|
|
||||||
global website_dir
|
global website_dir
|
||||||
website_dir = str(ROOT_DIR+"/Marvel")
|
website_dir = str(ROOT_DIR+"/Marvel")
|
||||||
elif request_count % 6 == 0:
|
elif session['requests'] % 6 == 0:
|
||||||
website_dir = str(ROOT_DIR+"/Escape")
|
website_dir = str(ROOT_DIR+"/Escape")
|
||||||
|
session.pop('requests', None)
|
||||||
else:
|
else:
|
||||||
global WEBSITE_DIRS
|
global WEBSITE_DIRS
|
||||||
try:
|
try:
|
||||||
|
@ -41,8 +39,12 @@ def static_proxy(filename):
|
||||||
# Serve site index.html
|
# Serve site index.html
|
||||||
@app.route('/', methods=['GET'])
|
@app.route('/', methods=['GET'])
|
||||||
def index():
|
def index():
|
||||||
|
if 'requests' in session:
|
||||||
|
session['requests'] += 1
|
||||||
|
else:
|
||||||
|
session['requests'] = 1
|
||||||
current_website_dir()
|
current_website_dir()
|
||||||
return send_from_directory(website_dir, 'index.html')
|
return send_from_directory(website_dir, 'index.html')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run()
|
app.run(debug=True)
|
||||||
|
|
Loading…
Reference in New Issue