-
Notifications
You must be signed in to change notification settings - Fork 28
/
generate_clues.py
88 lines (74 loc) · 2.6 KB
/
generate_clues.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
86
87
88
import os
import sys
import random
START_CLUE = 2
LAST_CLUE = 12
CLUE_SPACE = 100000
FIRST_CLUE = 12345
def zero_pad(clue):
l = len(str(clue))
m = len(str(CLUE_SPACE)) - 1
if l < m:
return "0"*(m-l) + str(clue)
else:
return str(clue)
def gen_clue_list(first, last, space, secret):
R = random.Random()
R.seed(secret)
clue_indexes = []
for i in range(first, last+1):
clue_indexes.append(R.randint(1, space))
clue_indexes[0] = FIRST_CLUE
return clue_indexes
if __name__ == "__main__":
if (len(sys.argv) != 2):
sys.exit("Need a single secret number, no spaces please")
try:
secret_number = int(sys.argv[1])
print("your secret number is: ", secret_number)
except ValueError:
print(sys.argv[1], "isn't a number")
try:
val = open("conf", "r").read().strip()
words = open(val, "r").read().strip()
except FileNotFoundError:
sys.exit("Unable to locate dictionary file. Please check README.md")
try:
os.stat("clues")
sys.exit("Clues folder already exists.")
except FileNotFoundError:
os.mkdir("clues")
clue_indexes = gen_clue_list(START_CLUE, LAST_CLUE,
CLUE_SPACE, secret_number)
try:
val = open("conf", "r").read().strip()
words = open(val, "r").read().strip()
except FileNotFoundError:
sys.exit("Unable to locate dictionary file. Please check README.md")
template_names = os.listdir(".clue-templates")
template_names.sort()
template_data = []
for t in template_names:
data = open(".clue-templates/" + t, "r").read()
template_data.append(data)
print("Hiding clues...")
for i in range(0, CLUE_SPACE):
dir_name = "clues/" + \
"0"*(len(str(CLUE_SPACE))-1 - len(str(i))) + str(i)
os.mkdir(dir_name)
file_name = open(dir_name + "/clue", "w")
if (i not in clue_indexes):
file_name.write("Nothing to see here.\n")
else:
template_index = clue_indexes.index(i)
if (template_index < len(template_data)):
if (template_index == 2):
#print template_index, clue_indexes[1]
file_name.write(template_data[template_index]
.format(zero_pad(clue_indexes[1]),
zero_pad(clue_indexes[0])))
else:
file_name.write(template_data[template_index])
else:
file_name.write("Clue: \n")
print("Done hiding clues.")