Skip to content

Instantly share code, notes, and snippets.

@svmotha
Created June 11, 2017 06:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svmotha/9095014150def6b84ecce3b61f1727af to your computer and use it in GitHub Desktop.
Save svmotha/9095014150def6b84ecce3b61f1727af to your computer and use it in GitHub Desktop.
Query and update DynamoDB tables using hash keys
from boto3.dynamodb.conditions import Key
class logCenter(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
# Update new followers to database (have already recieved direct messages)
def dynamoPut(self, follower, table):
table.put_item(
Item =
{
'follower_id': follower.id,
'screen_name': follower.screen_name,
}
)
return True
# Query database to check if follower is new or not
def dynamoQuery(self, follower, table):
response = table.query(
KeyConditionExpression=Key('follower_id').eq(follower.id)
)
items = response['Items']
if len(items) == 1:
found = True
return found, items
else:
found = False
return found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment