forked from Steeeephen/LAVA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
97 lines (65 loc) · 2.13 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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import flask
import os
import threading
from flask import render_template, request, send_from_directory, redirect
from assets.lava import LAVA
app = flask.Flask(
__name__, template_folder='assets/webui_templates', static_folder="output")
lava = LAVA()
version = lava.__version__
@app.route('/')
def home():
return render_template('home.html', version=version)
@app.route('/games')
def games():
directories = os.listdir('output')
directories.remove('positions')
return render_template('games.html', games=directories, version=version)
@app.route('/data')
def data():
games = os.listdir('output/positions')
games = [game.split('.')[0] for game in games]
return render_template('data.html', games=games, version=version)
@app.route('/download_data/<game>')
def download_data(game):
positions_directory = os.path.join(
'output',
'positions',
game)
return send_from_directory(positions_directory, game, as_attachment=True)
@app.route('/delete_data/<game>')
def delete_data(game):
positions_file = os.path.join(
'output',
'positions',
game)
os.remove(positions_file)
games = os.listdir('output/positions')
games = [game.split('.')[0] for game in games]
return redirect('/data')
@app.route("/input", methods=['GET', 'POST'])
def input():
if request.method == 'GET':
return render_template('input.html', version=version)
elif request.method == 'POST':
form = request.form
input_vars = [
'local',
'playlist',
'graphs',
'minimap',
'lightweight'
]
input_args = {'url': form['url']}
for var in input_vars:
input_args[var] = var in form
run_video_thread = threading.Thread(
target=lava.execute,
name="tracker",
kwargs=input_args
).start()
return render_template('input.html', version=version)
@app.route('/games/<video>')
def test(video):
return render_template('game.html', game=video, version=version)
app.run(debug=os.getenv('LAVA_DEBUG', False), port=8080)