-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan.py
More file actions
28 lines (23 loc) · 939 Bytes
/
scan.py
File metadata and controls
28 lines (23 loc) · 939 Bytes
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
import boto3 # import Boto3
def scan_devices(display_devices_data, dynamodb=None):
dynamodb = boto3.resource('dynamodb', endpoint_url="http://localhost:8000")
# Specify the table to scan
devices_table = dynamodb.Table('Smart_Farming1')
done = False
start_key = None
while not done:
if start_key:
scan_kwargs['ExclusiveStartKey'] = start_key
response = devices_table.scan()
display_devices_data(response.get('Items', []))
start_key = response.get('LastEvaluatedKey', None)
done = start_key is None
if __name__ == '__main__':
# A method for printing the items
def print_devices(devices):
for device in devices:
print(f"\n{device['DeviceID']} : {device['DataCount']}")
print(device['info'])
print(f"Scanning all devices data")
# Print the items returned
scan_devices(print_devices)