forked from pushingice/scavenger-hunt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_clues.py
executable file
·103 lines (81 loc) · 2.77 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
import os
import sys
import random
from shutil import rmtree
START_CLUE = 2
LAST_CLUE = 13
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__":
try:
print("Found existing scavenger hunt - updating clues...")
try:
rmtree("clues")
except:
pass
with open(".secret_number", "r") as f:
secret_number = int(f.read())
except:
if len(sys.argv) != 2:
sys.exit("Need a secret number - run like python generate_clues.py NUMBER")
secret_number = int(sys.argv[1])
try:
val = open("conf", "r").read().strip()
words = open(val, "r").read().strip()
except FileNotFoundError:
sys.exit("Unable to locate dictionary file. Please contact the instructors for support.")
try:
os.stat("clues")
except FileNotFoundError:
os.mkdir("clues")
clue_indexes = gen_clue_list(START_CLUE, LAST_CLUE, CLUE_SPACE, secret_number)
template_names = os.listdir(".clue-templates")
template_names.sort()
template_data = []
for t in template_names:
if t == "NO PEEKING":
continue
data = open(".clue-templates/" + t, "r").read()
template_data.append(data)
print("Hiding clues (this may take a couple minutes)...")
for i in range(0, CLUE_SPACE):
if i % 5000 == 0:
print(f"{i // 1000}% done...")
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")
with open(".secret_number", "w") as f:
f.write(str(secret_number))
print("Done hiding clues.")