Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
make it compatible with local
Browse files Browse the repository at this point in the history
  • Loading branch information
vggonzal authored and vggonzal committed Sep 18, 2023
1 parent f4ea941 commit 608dee6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
12 changes: 10 additions & 2 deletions hydrocronapi/controllers/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@
from typing import Generator
from boto3.dynamodb.conditions import Key
import boto3
import os

if os.environ['environment'] == 'local':
dynamodb_resource = boto3.resource('dynamodb',
aws_access_key_id="a",
aws_secret_access_key="a",
region_name="us-west-2",
endpoint_url="http://localhost:8000")
else:
dynamodb_resource = boto3.resource('dynamodb')

dynamodb = boto3.client('dynamodb')
dynamodb_resource = boto3.resource('dynamodb')
table = dynamodb_resource.Table('hydrocron_swot_reaches_test')

logger = logging.getLogger()
Expand Down
4 changes: 2 additions & 2 deletions hydrocronapi/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ paths:
schema:
type: string
format: date-time
example: 2022-08-23T00:00:00Z
example: 2023-08-23T00:00:00Z
- name: output
in: query
description: Format of the data returned
Expand Down Expand Up @@ -153,7 +153,7 @@ paths:
schema:
type: string
format: date-time
example: 2022-08-23T00:00:00Z
example: 2023-08-23T00:00:00Z
- name: output
in: query
description: Format of the data returned
Expand Down
30 changes: 30 additions & 0 deletions tests/example_load_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import boto3
import geopandas as gpd
import json
from decimal import Decimal

def upload():
table = boto3.resource('dynamodb',
aws_access_key_id="a",
aws_secret_access_key="a",
region_name="us-west-2",
endpoint_url="http://localhost:8000").Table('hydrocron_swot_reaches_test')

test_shapefile_path = 'tests/data/SWOT_L2_HR_RiverSP_Reach_548_011_NA_20230610T193337_20230610T193344_PIA1_01/SWOT_L2_HR_RiverSP_Reach_548_011_NA_20230610T193337_20230610T193344_PIA1_01.shp'

shp_file = gpd.read_file(test_shapefile_path)

item_attrs = {}
for index, row in shp_file.iterrows():
attributes = json.loads(row.to_json(default_handler=str), parse_float=Decimal)
for k,v in attributes.items():
if (str(k)=="time"):
item_attrs[k] = Decimal(v)
else:
item_attrs[k] = str(v)
print(str(k),str(v))

table.put_item(Item=item_attrs)

upload()

0 comments on commit 608dee6

Please sign in to comment.