forked from HowlingGoat/MGS_Name_Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetal_name_generator.py
More file actions
executable file
·115 lines (91 loc) · 3.61 KB
/
metal_name_generator.py
File metadata and controls
executable file
·115 lines (91 loc) · 3.61 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python
import random
import argparse
## Arg Parsing Section
parser = argparse.ArgumentParser(description='Randomly generate MGS type names.')
parser.add_argument('-e', '--extended', help='Use the extended names (Not present in game).', action='store_true')
parser.add_argument('-n', help='Generate n number of names.', default=1, type=int)
parser.add_argument('-f', '--first', help='Add custom first names files.', nargs='*')
parser.add_argument('-l', '--last', help='Add custom last name files.', nargs='*')
separator_help = """"Define a custom separator. If it's not working or not giving the desired
try using results 'single' or "double" quotes ' _ ' to help the parsing."""
parser.add_argument('-s', '--separator', help=separator_help, default=' ')
args = parser.parse_args()
n = args.n
extended = args.extended
args_first = args.first
args_last = args.last
separator = args.separator
## First in list will alway be run, every file preceding
# will be run in extended mode. This can be used to add permanently a file to
# the extended argument or to rename files.
first_files = ['First_Names.txt', 'First_Names_Extended.txt',]
last_files = ['Last_Names.txt', 'Last_Names_Extended.txt',]
## Change the separator, default is space.
# See the argparse argument
first_list = []
last_list = []
def add_lines(file_name, to_l):
"""Add lines to the proper list from a file."""
with open(file_name, 'rb') as f:
line = None
while True:
line = f.readline()
line_stripped = line.strip('\n').strip('\r')
line_lower = line_stripped.lower()
transformed_line = line_lower
if transformed_line == "":
break
else:
to_l.append(transformed_line)
def random_gen(list_name):
"""Generate a random number that maps to a entry in the specified list."""
number = len(list_name)
## Since it will be called from a list, has the range of 0 to len - 1
rand = random.randint(0, (number - 1) )
return rand
def generate_list(name_list, list_name):
"""Add items in the files to the list."""
## Add the main "official" list of names.
try:
add_lines(name_list[0], list_name)
except IOError:
exit('Sorry, the "%s" file is missing.' % name_list[0])
## Test for extended
if extended == True:
try:
for i in name_list[1:]:
add_lines(i, list_name)
except IOError:
exit('Sorry, the "%s" file is missing.' % i)
# Test for optional -f or -l.
try:
for i in args_first:
add_lines(i, list_name)
except TypeError:
## Case that -f or -l are not defined.
pass
except IOError:
exit('Sorry, I could not find "%s".' % i)
def main(count, separator, extended):
"""Main loop of the script. Generate both lists, then randomly selects
from that list depending on how much times are needed. Returns everything
as a list. extended can be set as true or false."""
to_return = []
## Generate lists
generate_list(first_files, first_list)
generate_list(last_files, last_list)
for i in range(count):
## Select the random number from the list of all possibilities.
rand_f = random_gen(first_list)
rand_l = random_gen(last_list)
title_name = first_list[rand_f].title() + " " + last_list[rand_l].title()
to_append = title_name.replace(" ", separator)
to_return.append(to_append)
return to_return
if __name__ == "__main__":
## Main loop
entries = main(n, separator, extended)
for i in entries:
print i
exit()