-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquoteDisplayer.py
More file actions
56 lines (39 loc) · 1.39 KB
/
Copy pathquoteDisplayer.py
File metadata and controls
56 lines (39 loc) · 1.39 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
from random import randint
import flask
app = flask.Flask(__name__)
# The file to read quotes from
myFile = "quotes.txt"
# Availiable background colors
colors = ["#0E7C7B", "#17BEBB", "#D62246", "#4B1D3F", "#2F1847", "#624763", "#540804", "#C75146", "#C75146"]
# Get the file contents
textFile = open(myFile, "r")
lines = textFile.read().splitlines()
fileLength = len(lines)
# To not repeat
quoteTimes = [0] * fileLength
lowestCount = 0
def getQuote():
global lowestCount
myNumber = randint(0, fileLength - 1)
i = 0
# Search for a quote that's been displayed least often
while quoteTimes[myNumber] is not lowestCount:
myNumber = randint(0, fileLength - 1)
i = i + 1
# If all the quotes have been displayed equally often, display any of them
if i == fileLength:
lowestCount = lowestCount + 1
# Keep track of how many times this quote has been displayed
quoteTimes[myNumber] = quoteTimes[myNumber] + 1
return lines[myNumber]
def getColor():
myNumber = randint(0, len(colors) - 1)
return colors[myNumber]
@app.route("/", methods=['POST', 'GET'])
def main():
return flask.render_template('index.html', quote=getQuote(), color=getColor())
@app.route('/favicon.ico')
def favicon():
return flask.redirect(flask.url_for('static', filename='images/favicon.ico'), code=302)
if __name__ == "__main__":
app.run(host="0.0.0.0")