-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
86 lines (67 loc) · 2.03 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
import ast
import requests
import time
from flask import Flask, render_template, request
# Instantiate Flask app/web server.
app = Flask(
__name__,
static_folder='/static/'
)
insults = requests.get("https://raw.githubusercontent.com/DavidRuoff/german-insults/master/src/index.json").text
insults = set(ast.literal_eval(insults))
app.config['TEMPLATES_AUTO_RELOAD'] = True
# Route for testing purposes.
@app.route('/')
def index():
return '<a href="/api/text/get/">TEXT API</a>'
text = 'I am a test'
textColor = 'white'
backgroundColor = 'purple'
# Route to get the text.
@app.route('/api/text/get/')
def api_get_text():
current_data = {
'text': text,
'textColor': textColor,
'backgroundColor': backgroundColor,
}
if request.args.get("long_poll", "true") == "false":
return current_data
for i in range(30):
new_data = {
'text': text,
'textColor': textColor,
'backgroundColor': backgroundColor,
}
if new_data != current_data:
return new_data
time.sleep(1)
return current_data
# Route to change the text.
@app.route('/api/text/change')
def api_change_text():
# Use variables from global scope.
global text, textColor, backgroundColor
args = dict(request.args)
# Figure out what variable the request wants to change.
if 'text' in args.keys():
if set([x.lower() for x in args['text'].split(" ")]) & insults:
text = 'NOOO! BAAAD!!! 😡'
else:
text = args['text']
elif 'textColor' in args.keys():
textColor = args['textColor']
elif 'backgroundColor' in args.keys():
backgroundColor = args['backgroundColor']
return {
'text': text,
'textColor': textColor,
'backgroundColor': backgroundColor,
}
# The display to show on a big screen.
@app.route('/display/')
def display():
return render_template('display.html')
# Run app if called directly.
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)