Skip to content

Commit 3928df5

Browse files
author
Micah J Martin
authored
Create generator.py
1 parent 1797ec4 commit 3928df5

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

generator.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import sys, random
2+
3+
def read(filename):
4+
words = {}
5+
with open(filename) as inf:
6+
lines = inf.readlines()
7+
i = 0
8+
choices = ["verb", "adjective1", "adjective2", "noun", "ending"]
9+
for c in choices:
10+
words[c] = []
11+
for l in lines:
12+
l = l.strip()
13+
if l == "":
14+
continue
15+
if l == "++" and i < len(choices):
16+
i+=1
17+
continue
18+
elif i >= len(choices):
19+
print("Done")
20+
break
21+
words[choices[i]] += [l]
22+
return words
23+
24+
def generate(words):
25+
output = ""
26+
output += random.choice(words["verb"]) +" "
27+
28+
if random.randint(1,7) == 1:
29+
output += random.choice(words["adjective1"]) +" "
30+
31+
output += random.choice(words["adjective2"]) +" "
32+
output += random.choice(words["noun"]) +" "
33+
if random.randint(1,9) == 1:
34+
output += random.choice(words["ending"])
35+
return output
36+
37+
38+
39+
if len(sys.argv) < 2:
40+
filename = "wordlist.txt"
41+
else:
42+
filename = sys.argv[1]
43+
44+
words = read(filename)
45+
46+
if len(sys.argv) > 2:
47+
try:
48+
count = int(sys.argv[2])
49+
except:
50+
pass
51+
else:
52+
count = 2
53+
54+
for i in range(count):
55+
print(generate(words))

0 commit comments

Comments
 (0)