from boto3.dynamodb.conditions import Key
import os
import re
+import sys
WEBROOT = "/srv/halibut.cworth.org/www"
end = ['</body>\n', '</html>\n']
html = start + expanding + columns + end
file = hunt_file(hunt, "index.html")
- f = open(file, "w")
+ f = open(file + ".tmp", "w")
for line in html:
f.write(line)
f.close()
+ os.rename(file + ".tmp", file)
return None
def round_overview(hunt, rnd, puzzles):
'</html>\n']
html = start + puzzle_list + end
file = hunt_file(hunt, "{}_round.html".format(filename_from_name(rnd)))
- f = open(file, "w")
+ f = open(file + ".tmp", "w")
for line in html:
f.write(line)
f.close()
+ os.rename(file + ".tmp", file)
return None
def puzzle_overview(hunt, puzzle):
'</body>\n',
'</html>\n']
file = hunt_file(hunt, "{}.html".format(filename_from_name(name)))
- f = open(file, "w")
+ f = open(file + ".tmp", "w")
for line in html:
f.write(line)
+ f.close()
+ os.rename(file + ".tmp", file)
return None
def puzzle_lists(hunt, puzzles, filt):
'</html>\n']
if filt == "All":
file1 = hunt_file(hunt, 'all.html')
- f = open(file1, "w")
+ f = open(file1 + ".tmp", "w")
for line in start + unsolved_code + solved_code + end:
f.write(line)
f.close()
+ os.rename(file1 + ".tmp", file1)
elif filt == "Solved":
file2 = hunt_file(hunt, 'solved.html')
- f = open(file2, 'w')
+ f = open(file2 + ".tmp", 'w')
for line in start + solved_code + end:
f.write(line)
f.close()
+ os.rename(file2 + ".tmp", file2)
elif filt == "Unsolved":
file3 = hunt_file(hunt, 'unsolved.html')
- f = open(file3, 'w')
+ f = open(file3 + ".tmp", 'w')
for line in start + unsolved_code + end:
f.write(line)
f.close()
+ os.rename(file3 + ".tmp", file3)
return None
-# Initialize AWS resources to talk to database
+def generate_for_hunt_id(table, hunt_id):
+ hunt, puzzles, rounds = hunt_info(table, hunt_id)
+
+ # Create a directory for the hunt in the WEBROOT
+ root = hunt_file(hunt, "")
+ try:
+ os.mkdir(root)
+ except FileExistsError:
+ # We're happy as a clam if the directory already exists
+ pass
+
+ overview(hunt, puzzles, rounds)
+ for rnd in rounds:
+ round_overview(hunt, rnd, puzzles)
+ for puzzle in puzzles:
+ puzzle_overview(hunt, puzzle)
+ puzzle_lists(hunt, puzzles, "All")
+ puzzle_lists(hunt, puzzles, "Solved")
+ puzzle_lists(hunt, puzzles, "Unsolved")
+
+# Initialize AWS resources to talk to the database
db = boto3.resource('dynamodb')
table = db.Table("turbot")
-hunt, puzzles, rounds = hunt_info(table, "mh2021")
-
-# Create a directory for the hunt in the WEBROOT
-root = hunt_file(hunt, "")
-try:
- os.mkdir(root)
-except FileExistsError:
- # We're happy as a clam if the directory already exists
- pass
-
-overview(hunt, puzzles, rounds)
-for rnd in rounds:
- round_overview(hunt, rnd, puzzles)
-for puzzle in puzzles:
- puzzle_overview(hunt, puzzle)
-puzzle_lists(hunt, puzzles, "All")
-puzzle_lists(hunt, puzzles, "Solved")
-puzzle_lists(hunt, puzzles, "Unsolved")
+
+def usage():
+ print("Usage: {} hunt_id [...]")
+ print("")
+ print("Generates pages (under {}) ".format(WEBROOT))
+ print("for the specified hunt_id(s).")
+
+if len(sys.argv) < 2:
+ usage()
+ sys.exit(1)
+
+for hunt_id in sys.argv[1:]:
+ generate_for_hunt_id(table, hunt_id)