2024-03-24 18:56:52 -05:00
|
|
|
import os
|
|
|
|
import random
|
2024-03-27 18:17:11 -05:00
|
|
|
from flask import Flask, send_from_directory, session
|
2024-03-24 18:56:52 -05:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
2024-03-27 18:17:11 -05:00
|
|
|
# Implement count to load specific page on Nth load
|
|
|
|
# Using session['requests']
|
|
|
|
app.secret_key = '420-69'
|
2024-03-26 20:36:43 -05:00
|
|
|
|
2024-03-24 18:56:52 -05:00
|
|
|
# Script must run from root dir containing all websites dirs
|
|
|
|
# OR change the ROOT_DIR path below :)
|
|
|
|
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))]
|
|
|
|
|
|
|
|
# Site choosing logic
|
|
|
|
website_dir = None
|
|
|
|
def current_website_dir():
|
2024-03-27 18:17:11 -05:00
|
|
|
if session['requests'] % 5 == 0:
|
2024-03-27 10:02:20 -05:00
|
|
|
global website_dir
|
|
|
|
website_dir = str(ROOT_DIR+"/Marvel")
|
2024-03-27 18:17:11 -05:00
|
|
|
elif session['requests'] % 6 == 0:
|
2024-03-27 16:18:03 -05:00
|
|
|
website_dir = str(ROOT_DIR+"/Escape")
|
2024-03-27 18:17:11 -05:00
|
|
|
session.pop('requests', None)
|
2024-03-27 10:02:20 -05:00
|
|
|
else:
|
2024-03-27 11:24:52 -05:00
|
|
|
global WEBSITE_DIRS
|
|
|
|
try:
|
2024-03-27 16:18:03 -05:00
|
|
|
WEBSITE_DIRS.remove('Escape')
|
2024-03-27 11:24:52 -05:00
|
|
|
WEBSITE_DIRS.remove('Marvel')
|
2024-03-27 16:18:03 -05:00
|
|
|
except (ValueError, IndexError) as e:
|
2024-03-27 11:24:52 -05:00
|
|
|
pass
|
2024-03-27 10:02:20 -05:00
|
|
|
website_dir = random.choice(WEBSITE_DIRS)
|
2024-03-27 16:18:03 -05:00
|
|
|
|
2024-03-24 18:56:52 -05:00
|
|
|
# Make static files available
|
|
|
|
@app.route('/<path:filename>', methods=['GET'])
|
|
|
|
def static_proxy(filename):
|
|
|
|
return send_from_directory(website_dir, filename)
|
|
|
|
|
|
|
|
# Serve site index.html
|
|
|
|
@app.route('/', methods=['GET'])
|
|
|
|
def index():
|
2024-03-27 18:17:11 -05:00
|
|
|
if 'requests' in session:
|
|
|
|
session['requests'] += 1
|
|
|
|
else:
|
|
|
|
session['requests'] = 1
|
2024-03-24 18:56:52 -05:00
|
|
|
current_website_dir()
|
2024-03-27 10:02:20 -05:00
|
|
|
return send_from_directory(website_dir, 'index.html')
|
2024-03-24 18:56:52 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-03-27 18:17:11 -05:00
|
|
|
app.run(debug=True)
|