-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (49 loc) · 1.41 KB
/
main.py
File metadata and controls
58 lines (49 loc) · 1.41 KB
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
from flask import Flask, render_template, request, redirect
from threading import Timer
import subprocess
import sys
app = Flask(__name__)
# params
command = []
try:
if len(sys.argv) > 1:
for i in range(1, len(sys.argv)):
command.append(sys.argv[i])
else:
command = ["pwd"]
except IndexError:
command = ["pwd"]
@app.route("/")
def fela_screen():
return render_template("index.html")
@app.route("/info", methods=['POST'])
def info_screen():
return redirect("/")
@app.route("/tickets", methods=['POST'])
def test_tickets():
if request.method == 'POST':
try:
Timer(1, subprocess_command).start()
return render_template("index.html")
except Exception as e:
print("*** Message: subprocess error. Redirecting.. ***")
return redirect("/")
def subprocess_command():
print("*** Message: run subprocess command ***")
try:
spo = subprocess.run(command, capture_output=True)
print(spo.stdout)
except Exception as e:
print(e)
def open_browser():
# set default page to http://127.0.0.1:5000/
# exit kiosk alt+F4
try:
subprocess.run(["chromium-browser", "--kiosk", "--app=http://127.0.0.1:5000/"])
except Exception as e:
print(e)
def main():
Timer(1, open_browser).start()
app.run(host='0.0.0.0', port=5000)
if __name__== "__main__":
main()