from boto3.dynamodb.conditions import Key
import os
import re
+import sys
WEBROOT = "/srv/halibut.cworth.org/www"
if puzzle['status'] == 'solved':
expanding += [' <tr class=\'solved\';>\n',
' <td>{}</td>\n'.format(link(website + filename_from_name(puzzle['name']) + ".html", puzzle['name']+meta)),
- ' <td>{}</td>\n'.format(puzzle['solution']),
+ ' <td>{}</td>\n'.format(", ".join(puzzle['solution']).upper()),
' </tr>\n']
else:
expanding += [' <tr class=\'unsolved\';>\n',
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):
' <td>{}</td>\n'.format(elink(puzzle.get('url',''), 'Puzzle')),
' <td>{}</td>\n'.format(elink(puzzle['sheet_url'], 'Sheet')),
' <td>{}</td>\n'.format(link(website + filename_from_name(puzzle['name']) + '.html', 'Overview')),
- ' <td>{}</td>\n'.format(puzzle['solution']),
+ ' <td>{}</td>\n'.format(", ".join(puzzle['solution']).upper()),
# ' <td></td>\n',
- ' <td>{}</td>\n'.format("".join(puzzle.get('tags',[]))),
+ ' <td>{}</td>\n'.format(", ".join(puzzle.get('tags',[]))),
' </tr>\n']
else:
puzzle_list += [ ' <tr>\n',
' <td>{}</td>\n'.format(link(website + filename_from_name(puzzle['name']) + '.html', 'Overview')),
' <td></td>\n',
# ' <td></td>\n',
- ' <td>{}</td>\n'.format(" ".join(puzzle.get('tags',[]))),
+ ' <td>{}</td>\n'.format(", ".join(puzzle.get('tags',[]))),
' </tr>\n']
end = [' </tbody>\n',
' </table>\n',
'</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):
else:
round_url = ''
if puzzle['status'] == 'solved':
- solution = puzzle['solution']
+ solution = ", ".join(puzzle['solution']).upper()
status = 'solved'
else:
solution = ""
' <table class="center">\n',
' <tr>\n',
' <td>Round(s): {}</td>\n'.format(" ".join(round_url)), #round page on our site
- ' <td>Tags: {}</td>\n'.format(" ".join(puzzle.get('tags',[]))), #add tags
+ ' <td>Tags: {}</td>\n'.format(", ".join(puzzle.get('tags',[]))), #add tags
' </tr>\n',
' <tr>\n',
' <td>Answer: {}</td>\n'.format(solution),
'</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):
' <td>{}</td>\n'.format(elink(puzzle.get('url',''), 'Puzzle')),
' <td>{}</td>\n'.format(elink(puzzle['sheet_url'], 'Sheet')),
' <td>{}</td>\n'.format(link(website + filename_from_name(puzzle['name']) + '.html', 'Overview')),
- ' <td>{}</td>\n'.format(puzzle['solution']),
+ ' <td>{}</td>\n'.format(", ".join(puzzle['solution']).upper()),
' <td>{}</td>\n'.format(round_url),
- ' <td>{}</td>\n'.format("".join(puzzle.get('tags',[]))),
+ ' <td>{}</td>\n'.format(", ".join(puzzle.get('tags',[]))),
' </tr>\n']
for puzzle in unsolved_puzzles:
if puzzle['type'] == 'meta':
' <td>{}</td>\n'.format(link(website + filename_from_name(puzzle['name']) + '.html', 'Overview')),
' <td></td>\n',
' <td>{}</td>\n'.format(round_url),
- ' <td>{}</td>\n'.format("".join(puzzle.get('tags',[]))),
+ ' <td>{}</td>\n'.format(", ".join(puzzle.get('tags',[]))),
' </tr>\n']
end = [' </tbody>\n',
' </table>\n',
'</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)