The return value is a dictionary suitable to be published to the
Slack views_publish API."""
- response = turb.db.Table("hunts").scan()
- hunts = response['Items']
+ # Behave cleanly if there is not hunts table at all yet.
+ try:
+ response = turb.db.Table("hunts").scan()
+ hunts = response['Items']
+ except:
+ hunts = []
return {
"type": "home",
import json
import re
import requests
+from botocore.exceptions import ClientError
TURBOT_USER_ID = 'U01B9QM4P9R'
"Hunt ID can only contain letters, "
+ "numbers, and underscores")
+ # Check to see if the hunts table exists
+ hunts_table = turb.db.Table("hunts")
+
+ try:
+ exists = hunts_table.table_status in ("CREATING", "UPDATING",
+ "ACTIVE")
+ except ClientError:
+ exists = False
+
+ # Create the hunts table if necessary.
+ if not exists:
+ hunts_table = turb.db.create_table(
+ TableName='hunts',
+ KeySchema=[
+ {'AttributeName': 'channel_id', 'KeyType': 'HASH'},
+ ],
+ AttributeDefinitions=[
+ {'AttributeName': 'channel_id', 'AttributeType': 'S'},
+ ],
+ ProvisionedThroughput={
+ 'ReadCapacityUnits': 5,
+ 'WriteCapacityUnits': 5
+ }
+ )
+ return submission_error("hunt_id",
+ "Still bootstrapping hunts table. Try again.")
+
# Create a channel for the hunt
try:
response = turb.slack_client.conversations_create(name=hunt_id)
# Create a sheet for the channel
sheet = turbot.sheets.sheets_create(turb, hunt_id)
+ channel_id = response['channel']['id']
+
# Insert the newly-created hunt into the database
- hunts_table = turb.db.Table("hunts")
hunts_table.put_item(
Item={
'channel_id': channel_id,