forked from sheggen/Scrolling-Font-Changer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
129 lines (110 loc) · 2.82 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from flask import Flask, render_template, request, redirect, url_for
import threading, time
app = Flask(__name__)
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
@app.route('/young')
def young():
return render_template("main.html", age = "young")
@app.route('/old')
def old():
return render_template("main.html", age = "old")
@app.route('/editDisplay')
def editDisplay():
f = open('currentFont.txt', 'r')
font = f.readline()
f.close()
return render_template("editDisplay.html", font = font)
@app.route('/getWords')
def getWords():
f = open('currentFont.txt', 'r')
font = f.readline()
# print(font)
f.close()
f = open('words.txt', 'r')
words = f.read()
f.close()
f = open('muteDisplay.txt', 'r')
muter = f.read()
f.close()
return muter + "||" + font + "||" + words
@app.route('/vetWords')
def vetWords():
f = open('pendingWords.txt', 'r')
words = f.readlines()
print(words)
f.close()
f = open('words.txt', 'r')
vettedWords = f.readlines()
return render_template("vetWords.html", words = words, vettedWords = vettedWords)
@app.route('/approve/<word>')
def approve(word):
f = open('words.txt', 'a')
f.write(word + "\n")
f.close()
with open('pendingWords.txt', 'r') as f:
lines = f.readlines()
with open('pendingWords.txt', 'w') as f:
# Remove word from pendingWords that was approved
for line in lines:
print("Line: ", line.strip())
print("word: ", word.strip())
print("Evaluated: ", line.strip() != word.strip())
if line.strip() != word.strip():
print("adding", word, line.strip("\n"))
f.write(line)
else:
print("Skipping: ", line)
f = open('pendingWords.txt', 'r')
words = f.read()
f.close()
if len(words) > 0:
return words
else:
return ""
@app.route('/removeWord', methods = ["POST"])
def removeWord():
word = request.form.get("word")
f = open('pendingWords.txt', 'r')
words = f.read()
words = words.replace(word, " ")
f = open('pendingWords.txt', 'w')
f.write(words)
f.close()
return redirect(url_for('vetWords'))
@app.route('/sendWord/<age>/<word>')
def sendWord(age, word):
f = open('pendingWords.txt', 'a')
f.write(age + ": " + word.strip() + ":|: \n")
f.close()
return word
@app.route('/sendFont/<font>')
def sendFont(font):
f = open('currentFont.txt', 'w')
f.write(font)
f.close()
return font
@app.route('/getFont')
def getFont():
f = open('currentFont.txt', 'r')
font = f.read()
print(font)
f.close()
return font
def updateMuteState():
states = {"true": "false",
"false": "true",
"": "true"}
f = open('muteDisplay.txt', 'r')
currentState = f.read()
f = open('muteDisplay.txt', 'w')
f.write(states[currentState])
f.close()
@app.route('/muteDisplay')
def muteDisplay():
updateMuteState()
threading.Timer(20.0, updateMuteState).start()
f = open('muteDisplay.txt', 'r')
currentState = f.read()
f.close()
return currentState