+def get_table_item(turb, table_name, key, value):
+ """Get an item from the database 'table_name' with 'key' as 'value'
+
+ Returns a tuple of (item, table) if found and (None, None) otherwise."""
+
+ table = turb.db.Table(table_name)
+
+ response = table.get_item(Key={key: value})
+
+ if 'Item' in response:
+ return (response['Item'], table)
+ else:
+ return None
+
+def channel_is_puzzle(turb, channel_id, channel_name):
+ """Given a channel ID/name return the database item for the puzzle
+
+ If this channel is a puzzle, this function returns a tuple:
+
+ (puzzle, table)
+
+ Where puzzle is dict filled with database entries, and table is a
+ database table that can be used to update the puzzle in the
+ database.
+
+ Otherwise, this function returns (None, None)."""
+
+ hunt_id = channel_name.split('-')[0]
+
+ # Not a puzzle channel if there is no hyphen in the name
+ if hunt_id == channel_name:
+ return (None, None)
+
+ return get_table_item(turb, hunt_id, 'channel_id', channel_id)
+
+def channel_is_hunt(turb, channel_id):
+
+ """Given a channel ID/name return the database item for the hunt
+
+ Returns a dict (filled with database entries) if there is a hunt
+ for this channel, otherwise returns None."""
+
+ return get_table_item(turb, "hunts", 'channel_id', channel_id)
+