-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathengine.py
33 lines (25 loc) · 846 Bytes
/
engine.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
from random import randint
quote_file = "quotes.txt"
def get_random_quote():
start_line = None
end_line = None
# Open the quote file
with open(quote_file) as file:
line = file.readlines()
# Let's begin with some random line number
# When '%%' is found, save the line number and break the loop
for i in range(len(line)-1):
random_line = (randint(0, len(line)-1))
if "%%" in line[random_line]:
start_line = random_line
break
# Find the closest next '%%' line number
for i in range(start_line+1, len(line)):
if "%%" in line[i]:
end_line = i
break
# We don't need the '%%' to be printed
start_line += 1
# Join all the text between these two '%%'
quote = "".join(line[start_line:end_line])
return quote