X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=html_generator.py;h=c16f033552cb80094befa995b04645fa1d612ba6;hb=d443dffc599f0f858068bd22dcf289fcbe4d64f3;hp=e75f14836921015be8247fa1ea5d25a153d12b71;hpb=5eb6c0e95cb218e6aa7b7c61613e9a73d526549b;p=turbot-web diff --git a/html_generator.py b/html_generator.py index e75f148..c16f033 100644 --- a/html_generator.py +++ b/html_generator.py @@ -14,24 +14,31 @@ that would be great Requires sorttable.js, which should be included """ +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 filename_from_name(name): + """Returns a string derived from name, but with all spaces and slashes + replaced with underscores, (for making a clean filename)""" + return re.sub(r'[ /]', '_', name) + 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(turb, hunt_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) @@ -42,10 +49,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-') @@ -63,15 +70,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: @@ -163,7 +172,7 @@ def overview(puzzles, rounds): expanding += [ '