-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·54 lines (36 loc) · 1.23 KB
/
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
#!/usr/bin/env python3
import flask
from flask import url_for
import oblique_strategies
API_PATH = "/api/v1"
app = flask.Flask(__name__)
def get_strategy(ed=None):
if ed is None:
return oblique_strategies.get_random_strat()
elif ed < 1 or ed > len(oblique_strategies.STRATEGIES):
flask.abort(404)
else:
return oblique_strategies.get_random_strat(ed)
def get_strategy_html(ed=None):
strategy, edition = get_strategy(ed)
return flask.render_template("strategy.html", strategy=strategy)
@app.route("/")
def show_random_strat():
html = get_strategy_html()
return html
@app.route("/<int:ed>")
def show_random_strat_from_edition(ed):
html = get_strategy_html(ed)
return html
@app.route(API_PATH + "/")
def get_random_strat():
strategy, edition = get_strategy()
return {"strategy": strategy, "edition": edition}
@app.route(API_PATH + "/<int:ed>")
def get_random_strat_from_edition(ed):
strategy, edition = get_strategy(ed)
return {"strategy": strategy, "edition": edition}
# Get any strategy: curl -L http://127.0.0.1:5000/api/v1 -X GET
# Get a strategy from first edition: curl http://127.0.0.1:5000/api/v1/1 -X GET
if __name__ == "__main__":
app.run(debug=True)