-
Notifications
You must be signed in to change notification settings - Fork 0
/
tox.ini
43 lines (34 loc) · 1.02 KB
/
tox.ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from __future__ import print_function # Python 2/3 compatibility
import boto3
import json
import decimal
import time
from boto3.dynamodb.conditions import Key, Attr
import base64
import ast
# Helper class to convert a DynamoDB item to JSON.
class DecimalEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, decimal.Decimal):
if o % 1 > 0:
return float(o)
else:
return int(o)
return super(DecimalEncoder, self).default(o)
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('hashtags')
print("Popular Hashtags")
response = table.scan()
def gun(response):
x=[]
for i in response['Items']:
d = ast.literal_eval((json.dumps(i, cls=DecimalEncoder)))
f=d["htCount"]
x.append(d)
x.sort(cmp=lambda r,y: cmp(r["htCount"], y["htCount"]), reverse=True)
return x
def lambda_handler(event, context):
response = table.scan()
event = gun(response)
return event
lambda_handler(event,context)