Created
June 11, 2017 06:45
-
-
Save svmotha/9095014150def6b84ecce3b61f1727af to your computer and use it in GitHub Desktop.
Query and update DynamoDB tables using hash keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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