]> git.cworth.org Git - turbot/blob - turbot/puzzle.py
9f9b1c600b4002a5afa661cdf1d4c9b930639fd0
[turbot] / turbot / puzzle.py
1 from boto3.dynamodb.conditions import Key
2
3 def find_puzzle_for_url(turb, hunt_id, url):
4     """Given a hunt_id and URL, return the puzzle with that URL
5
6     Returns None if no puzzle with the given URL exists in the database,
7     otherwise a dictionary with all fields from the puzzle's row in
8     the database.
9     """
10
11     response = turb.table.query(
12         IndexName='url_index',
13         KeyConditionExpression=(
14             Key('hunt_id').eq(hunt_id) &
15             Key('url').eq(url)
16         )
17     )
18
19     if response['Count'] == 0:
20         return None
21
22     return response['Items'][0]