-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
34 lines (26 loc) · 855 Bytes
/
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
from flask import Flask, render_template
import json
from datetime import datetime
app = Flask(__name__)
boards = {
"default": "/home/werewolf/leaderboard.json"
}
def get_leaderboard(name=None):
if name not in boards:
name = "default"
with open(boards[name], "rt") as f:
return boards[name], json.load(f)
@app.context_processor
def helpers():
return dict(
sorted=sorted,
format_date=lambda d: datetime.strptime(d, "%Y-%m-%dT%H:%M:%SZ").strftime("%Y-%m-%d %H:%M:%S (UTC)"),
with_precision=lambda n, precision: format(n, ".{}f".format(precision))
)
@app.route("/")
@app.route("/<board_name>/")
def get_board(board_name="default"):
url, board = get_leaderboard(board_name)
return render_template("index.html", url=url, board=board)
if __name__ == '__main__':
app.run(port=5000)