-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrelease_namer.py
68 lines (54 loc) · 1.69 KB
/
release_namer.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
import random
from argparse import ArgumentParser
def options():
parser = ArgumentParser()
parser.add_argument(
'-l',
'--letter',
dest="letter",
required=True,
help="What letter should this release name start with?"
)
parser.add_argument(
'-a',
'--adjectives',
dest="adjectives",
default="adjectives.txt",
help="Path to text file containing adjectives"
)
parser.add_argument(
'-n',
'--nouns',
dest="nouns",
default="nouns.txt",
help="Path to text file containing nouns"
)
parser.add_argument(
'-s',
'-shakespeare',
dest="shakespear",
action="store_true",
help="Use Shakespearean terms"
)
return parser.parse_args()
def get_sublist(names, letter):
return [name for name in names if name.lower().startswith(letter)]
if __name__ == "__main__":
options = options()
letter = options.letter.lower()
nouns_file = options.nouns
adjectives_file = options.adjectives
if options.shakespear == True:
nouns_file="shakespearean_nouns.txt"
adjectives_file="shakespearean_adjectives.txt"
with open(adjectives_file) as a:
adjectives = [line.rstrip() for line in a]
with open(nouns_file) as n:
nouns = [line.rstrip() for line in n]
adjectives = get_sublist(adjectives, letter)
nouns = get_sublist(nouns, letter)
if adjectives and nouns:
print("{} {}".format(random.choice(adjectives),
random.choice(nouns)).title())
else:
print("Sorry, no names available for that letter. Try again.")