|  | from flask import Flask, render_template, redirect, request
from time import time
from urllib.parse import urlparse, unquote
from markdown2 import markdown
import requests
import json
from bs4 import BeautifulSoup
app = Flask(
    __name__,
    static_url_path='',
    static_folder='static/',
    template_folder='templates/'
)
@app.route('/')
def index():
    return render_template("index.html", nightly=False)
@app.route('/nightly')
def nightly():
    return render_template("index.html", nightly=True)
@app.route('/agegate')
def agegate():
    url = request.args.get("to", default=None)
    try:
        if urlparse(url).netloc and urlparse(url).netloc[-9:] != "crux.sexy":
            print("URL is not pointing at crux.sexy")
            url = "https://crux.sexy/"
    except:
        url = "https://crux.sexy"
    try:
        r = requests.get(url, cookies={"agegate": "true"})
        
        soup = BeautifulSoup(r.text, "html5lib")
        headers = []
        for item in soup.head.findAll("meta"):
            if item.has_attr("name") and item["name"] == "viewport":
                continue
            if item.has_attr("content"):
                headers.append(str(item))
    except:
        headers = []
    return render_template("age-gate.html", url=url, headers="\n".join(headers))
@app.route('/accept')
def accept():
    url = request.args.get("url", default=None)
    if urlparse(url).netloc and urlparse(url).netloc[-9:] != "crux.sexy":
        print("oops")
        url = "/"
    if not url:
        url = "/"
    res = redirect(url, 307)
    res.set_cookie("agegate", "true", time() + 60*60*24*365, domain="crux.sexy")
    return res
@app.route('/changelog')
def changelog():
    game_names = ["stroll", "feast", "gorge", "satiate", "macrovision"]
    games = []
    for game in game_names:
        data = json.load(open("{0}/changelog.json".format(game)))
        keys = sorted(data.keys())[::-1]
        versions = []
        for key in keys:
            versions.append({"version": key, "changes": markdown(data[key])})
        games.append({"name": game, "versions": versions})
    return render_template("changelog.html", games=games)
@app.route('/commits')
def commits():
    game_names = ["stroll", "feast", "gorge", "satiate", "macrovision"]
    games = []
    for game in game_names:
        data = json.load(open("commits/{0}.json".format(game)))
        games.append({"name": game, "commits": data})
    return render_template("commits.html", games=games)
if __name__ == "__main__":
    app.run(debug=True, host='0.0.0.0', port=5002)
 |