X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=html_generator.py;h=3ee751c989348e6c5004ec399fa6dc403f4972be;hb=72e26f791228ad95c4cc5bd67eba4e0d23396f63;hp=9b1b1147bb966012b97aeef4331aefb0899fa27a;hpb=2190ac00d55a00d00f141fc14f0e8a65a47a49dd;p=turbot-web diff --git a/html_generator.py b/html_generator.py index 9b1b114..3ee751c 100644 --- a/html_generator.py +++ b/html_generator.py @@ -14,20 +14,26 @@ that would be great Requires sorttable.js, which should be included """ -from turbot.channel import channel_url +import boto3 from boto3.dynamodb.conditions import Key +import re website = "https://halibut.cworth.org/" #change this if we're using AWS or some other subdomain instead -def find_hunt_for_hunt_id(turb, hunt_id): +def channel_url(channel_id): + """Given a channel ID, return the URL for that channel.""" + + return "https://halibutthatbass.slack.com/archives/{}".format(channel_id) + +def find_hunt_for_hunt_id(table, hunt_id): """Given a hunt ID find the database item for that hunt Returns None if hunt ID is not found, otherwise a dictionary with all fields from the hunt's row in the table, (channel_id, active, hunt_id, name, url, sheet_url, etc.). """ - response = turb.table.get_item( + response = table.get_item( Key={ 'hunt_id': hunt_id, 'SK': 'hunt-{}'.format(hunt_id) @@ -38,10 +44,10 @@ def find_hunt_for_hunt_id(turb, hunt_id): else: return None -def hunt_puzzles_for_hunt_id(turb, hunt_id): +def hunt_puzzles_for_hunt_id(table, hunt_id): """Return all puzzles that belong to the given hunt_id""" - response = turb.table.query( + response = table.query( KeyConditionExpression=( Key('hunt_id').eq(hunt_id) & Key('SK').begins_with('puzzle-') @@ -59,15 +65,17 @@ def link(lin, text): #internal links, doesn't open new tab return '{}'.format(lin, text) -def hunt_info(turb, hunt): +def hunt_info(table, hunt_id): """ Retrieves list of rounds, puzzles for the given hunt """ + + hunt = find_hunt_for_hunt_id(table, hunt_id) + name = hunt["name"] - hunt_id = hunt["hunt_id"] channel_id = hunt["channel_id"] - puzzles = hunt_puzzles_for_hunt_id(turb, hunt_id) + puzzles = hunt_puzzles_for_hunt_id(table, hunt_id) rounds = set() for puzzle in puzzles: @@ -319,7 +327,8 @@ def puzzle_overview(puzzle): '\n', '\n', '\n'] - underscored = "_".join(name.split()) + # Replace all spaces and slashes in the name with underscores + underscored = re.sub(r'[ /]', '_', name) file = "{}.html".format(underscored) f = open(file, "w") for line in html: @@ -424,10 +433,11 @@ def puzzle_lists(puzzles, filt): f.close() return None +# Initialize AWS resources to talk to database +db = boto3.resource('dynamodb') +table = db.Table("turbot") +puzzles, rounds = hunt_info(table, "mh2021") - -puzzles, rounds = hunt_info(turb, hunt) -#I am not sure where these come from overview(puzzles, rounds) for rnd in rounds: round_overview(rnd, puzzles)