From d0fb115838dd90a089cd44ecd63fc84c84389ce6 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 12 Jan 2022 00:05:06 -0800 Subject: [PATCH] Drop the top-level "turb" data structure In the original turbot code, this was a simple structure to hold on to all the things necessary for turbot. Specifically, it had a boto connection to the database, a handle for the Google sheets API, and a handle for the Slack client API. In this code, the only one of those things we talk to is the DynamoDB table so that's all we need here. --- html_generator.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/html_generator.py b/html_generator.py index e75f148..9eee85c 100644 --- a/html_generator.py +++ b/html_generator.py @@ -24,14 +24,14 @@ def channel_url(channel_id): 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 +42,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 +63,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: @@ -428,10 +430,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) -- 2.43.0