X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;ds=sidebyside;f=turbot%2Fpuzzle.py;h=b6e78833098f9ed2c4d5251a82400d01941c9b07;hb=ac83e42a735ae1098ebcec783b5f816369eb3917;hp=81e0630f88c08416097ec55aa972ccde18387164;hpb=4f287a0e6b54f57529162c555c2502b3726d1edd;p=turbot diff --git a/turbot/puzzle.py b/turbot/puzzle.py index 81e0630..b6e7883 100644 --- a/turbot/puzzle.py +++ b/turbot/puzzle.py @@ -5,6 +5,25 @@ from turbot.channel import channel_url from boto3.dynamodb.conditions import Key import re +def find_puzzle_for_puzzle_id(turb, hunt_id, puzzle_id): + """Given a hunt_id and puzzle_id, return that puzzle + + Returns None if no puzzle with the given hunt_id and puzzle_id + exists in the database, otherwise a dictionary with all fields + from the puzzle's row in the database. + """ + + response = turb.table.get_item( + Key={ + 'hunt_id': hunt_id, + 'SK': 'puzzle-{}'.format(puzzle_id) + }) + + if 'Item' in response: + return response['Item'] + else: + return None + def find_puzzle_for_url(turb, hunt_id, url): """Given a hunt_id and URL, return the puzzle with that URL