-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_data.py
23 lines (19 loc) · 921 Bytes
/
load_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import json # module for converting Python objects to JSON
# decimal module support correctly-rounded decimal floating point arithmetic.
from decimal import Decimal
import boto3 # import Boto3
def load_data(devices, dynamodb = None):
dynamodb = boto3.resource('dynamodb', endpoint_url = "http://localhost:8000")
devices_table = dynamodb.Table('IotDevice')
# Loop through all the items and load each
for device in devices:
device_id = (device['device_id'])
datacount = device['datacount']
# Print device info
print("Loading Devices Data:", device_id, datacount)
devices_table.put_item(Item = device)
if __name__ == '__main__':
# open file and read all the data in it
with open("C:/Users/Lenovo/Desktop/DynamoDB/data.json") as json_file:
device_list = json.load(json_file, parse_float = Decimal)
load_data(device_list)