bring/app.py

59 lines
1.5 KiB
Python

import json
from flask import Flask, redirect, render_template
from markupsafe import escape
from waitress import serve
reader = open("users.json", "r")
data = json.loads(reader.read())
reader.close()
users = data["users"]
websites = data["websites"]
app = Flask(__name__, static_url_path='',
static_folder='web/static',
template_folder='web/templates')
@app.route("/<name>/next")
def getNextUser(name):
if(not name in users):
return "user not found."
nextUserId = users.index(name) + 1
if(nextUserId == len(users)):
nextUserId = 0
return redirect(websites[nextUserId])
@app.route("/<name>/previous")
def getPreviousUser(name):
if(not name in users):
return "user not found."
nextUserId = users.index(name) - 1
if(nextUserId == -1):
nextUserId = len(users) -1
print(nextUserId)
return redirect(websites[nextUserId])
@app.route("/<name>")
def getUserWebsite(name):
if(not name in users):
return "user not found."
return redirect(websites[users.index(name)])
@app.route("/users")
def listUsers():
thingToGive = ""
for user in users:
thingToGive = thingToGive + f"<a href=\"{websites[users.index(user)]}\" target=\"_blank\">{user}</a><br>"
return "<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"/css/users.css\"></head><body>"+ thingToGive+"<body><html>"
@app.route("/")
def home():
return render_template('index.html')
if __name__ == '__main__':
serve(app, host='127.0.0.1', port=9932)