]> git.cworth.org Git - turbot-web/commitdiff
Accept the name(s) of hunt_ids which should be generated on the command line
authorCarl Worth <cworth@cworth.org>
Wed, 12 Jan 2022 09:38:45 +0000 (01:38 -0800)
committerCarl Worth <cworth@cworth.org>
Wed, 12 Jan 2022 09:38:45 +0000 (01:38 -0800)
With this, this script can now be used to generate files for mutliple
hunts in a single run.

html_generator.py

index de7291c2518076e0e8e17b02cfd3e6cfe5652fae..7d2c318fbd09293fccec6e371c1f1b76ade0efd9 100644 (file)
@@ -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)