From 7d560553537d040a217e5467008bee5afd9f6aa9 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 12 Jan 2022 01:38:45 -0800 Subject: [PATCH] Accept the name(s) of hunt_ids which should be generated on the command line With this, this script can now be used to generate files for mutliple hunts in a single run. --- html_generator.py | 54 ++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/html_generator.py b/html_generator.py index de7291c..7d2c318 100644 --- a/html_generator.py +++ b/html_generator.py @@ -18,6 +18,7 @@ import boto3 from boto3.dynamodb.conditions import Key import os import re +import sys WEBROOT = "/srv/halibut.cworth.org/www" @@ -455,24 +456,39 @@ def puzzle_lists(hunt, puzzles, filt): f.close() 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) -- 2.43.0