-
Notifications
You must be signed in to change notification settings - Fork 1
/
b9_app.py
85 lines (73 loc) · 2.18 KB
/
b9_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
import codecs
import os
import re
import textwrap
from bs4 import BeautifulSoup as Soup
import actor
from script import Script
# Edit this as appropriate to add more people to the final output
CAST = [
"BEVERLY",
"COMPUTER",
"DATA",
"DIRECTION",
"GEORDI",
"PICARD",
"RIKER",
"TROI",
"WESLEY",
"WORF",
]
CURRENT_FILE_PATH = os.path.abspath(__file__)
SCRIPTS_DIRECTORY = f"{os.path.split(CURRENT_FILE_PATH)[0]}/scripts/"
# Get raw text as string, splitting each line into a two-item list of actor name and text
with open(SCRIPTS_DIRECTORY + "source_scripts.txt") as f:
all_tng_text = [line.split(" | ") for line in f.readlines()]
if __name__ == "__main__":
word_count = 0
while word_count <= 1000:
try:
word_count = int(input("Enter an integer wordcount greater than 1000: "))
except ValueError:
print(f"{word_count} isn’t an integer…")
word_count = 0
else:
if word_count > 1000:
break
with codecs.open(
f"{os.path.split(CURRENT_FILE_PATH)[0]}/output/output.html", "w", "utf-8"
) as output:
tng_actors = {
member: actor.Actor(all_tng_text, member, CAST, 3) for member in CAST
}
script = Script(1000, tng_actors)
html = textwrap.dedent(
"""\
<html lang='en'>
<head>
<title>B-9 Indifference</title>
<meta charset='UTF-8'>
<link href='styles.css' rel='stylesheet'/>
</head>
<body>
"""
)
while word_count > 0:
episode_text = script.generate_episode()
episode_length = len(
list(
filter(
None, re.split(r"\s+", re.sub(r"<(.*?)>+", "", episode_text))
)
)
)
html += episode_text
word_count -= episode_length
html += textwrap.dedent(
"""
</body>
</html>
"""
)
soup = Soup(html, "html.parser")
print(soup.prettify(), file=output)