forked from Sin-tel/temper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flask_app.py
80 lines (57 loc) · 1.95 KB
/
flask_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import flask as f
import traceback
import git
from timeout import time_limit, TimeoutException
from info import *
# from werkzeug.middleware.profiler import ProfilerMiddleware
app = f.Flask(__name__)
# app.wsgi_app = ProfilerMiddleware(app.wsgi_app)
@app.route("/")
def index():
return f.render_template("./temper.html")
@app.route("/result", methods=["POST", "GET"])
def result():
if f.request.method == "GET":
args = f.request.args
args = args.to_dict()
args["tenney"] = "tenney" in args
args["reduce"] = args.get("reduce")
if "submit_edo" in args:
temp = from_edos(args)
elif "submit_comma" in args:
temp = from_commas(args)
else:
raise ValueError("nothing submitted")
try:
with time_limit(5):
html_info = info(temp, args)
except TimeoutException as e:
raise TimeoutException("Calculation took too long!") from e
print("", flush=True)
return f.render_template("./result.html", res=html_info)
@app.route("/update", methods=["POST"])
def update():
if f.request.method == "POST":
repo = git.Repo("./temper")
origin = repo.remotes.origin
if not "main" in repo.heads:
repo.create_head("main", origin.refs.main)
repo.heads.main.set_tracking_branch(origin.refs.main).checkout()
origin.pull()
return "", 200
return "", 400
@app.route("/xen")
def xen():
return '<img src="static/xen.png" width="550">'
@app.route("/test")
def test():
return "hey"
@app.errorhandler(500)
def internal_error(exception):
print("500 error caught")
return "<pre>" + traceback.format_exc() + "</pre>"
if __name__ == "__main__":
# app.run(host="127.0.0.1", debug=True)
app.run(debug=True)
# app.run(debug=True, threaded=True)
# app.run(threaded=True)