-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
68 lines (51 loc) · 1.81 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
import os
import subprocess
from flask import *
from config import *
import logging
LIGHTS_HOME = get_home()
app = Flask(__name__)
app.config["DEBUG"] = True
bp = Blueprint('application_context', __name__, template_folder='templates')
logger = logging.getLogger('Lights')
p = None
@bp.route('/arrange/<section>', methods=['GET'])
def home(section):
global p
if p is not None:
p.kill()
p = subprocess.Popen("exec python3 " + LIGHTS_HOME + "child_process.py " + section, shell=True)
return "<h1>"+get_context()+" Lights!</h1><p>" + str(section) + "</p>"
@bp.route('/status', methods=['GET'])
def status():
global p
if p is not None:
state = f"running [{p.args}]." if p.poll() is None else "finished running."
return f"Subprocess {state}"
else:
return "No subprocess initialized."
@bp.route('/custom/', methods=['GET'])
def custom():
if request.args.get('colorValue'):
color_value = request.args.get('colorValue').lstrip("#")
print(color_value)
rgb = tuple(int(color_value[i:i + 2], 16) for i in (0, 2, 4))
print(rgb)
global p
if p is not None:
p.kill()
p = subprocess.Popen(
"exec python3 " + LIGHTS_HOME + "child_process.py custom "
+ str(rgb[0]) + " " + str(rgb[1]) + " " + str(rgb[2]),
shell=True)
return render_template(FILE_NAME_CUSTOM, context=get_context())
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico',
mimetype='image/vnd.microsoft.icon')
@bp.route('/')
def render_home():
return render_template('home.html', context=get_context())
app.register_blueprint(bp, url_prefix=get_context())
if __name__ == '__main__':
app.run(host='0.0.0.0')