-
Notifications
You must be signed in to change notification settings - Fork 0
/
fictionamer.py
81 lines (65 loc) · 2.17 KB
/
fictionamer.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
#======================================#
# Fictionamer #
# by Randall Arms #
# github.com/randallarms/fictionamer #
#======================================#
from random import randint
import os
# Opening text
print("\n\n=========")
print("Fictionamer")
print("=========")
print("Generate a name!")
# Input variable
g = "9.81 m/s^2"
# Genres (to be added: steampunk)
genres = ["fantasy", "scifi", "horror"]
# Name generation function
def name_gen(genre):
if not genre in genres:
return False
# Determine gender
gender = "male"
if randint(0,1) == 0:
gender = "female"
# Get files
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
f_prefix = open(os.path.join(__location__, "names/" + genre + "/prefix_" + gender + ".txt"), "r")
f_name = open(os.path.join(__location__, "names/" + genre + "/name_" + gender + ".txt"), "r")
f_suffix = open(os.path.join(__location__, "names/" + genre + "/suffix_" + gender + ".txt"), "r")
# Fill list of possible names from file
prefixes = []
names = []
suffixes = []
for line in f_prefix:
prefixes.append(line)
for line in f_name:
names.append(line)
for line in f_suffix:
suffixes.append(line)
# Generate name
name_str = ""
if randint(0,2) == 0:
name_str += prefixes[randint(0, len(prefixes)-1)].strip('\n') + " "
name_str += names[randint(0, len(names)-1)].strip('\n')
name_str += " " + names[randint(0, len(names)-1)].strip('\n')
if randint(0,5) == 0:
name_str += ", " + suffixes[randint(0, len(suffixes)-1)].strip('\n')
return name_str
file.close()
# Run the prompt and results
while g != "exit":
# Get the genre
print("\nEnter a genre to generate a name, or enter \"exit\" to end. ")
g = input("> ");
# Generate the name
name = name_gen(g)
# Print the results
if g == "exit":
print("\nThank you for using Fictionamer. Goodbye! ")
exit()
elif name == False:
print("\nGenre not found! ")
else:
print("\nGenerated name: ")
print(name + "\n")