From 00a968a33e14400f07c7d53f0cf02ff993346b57 Mon Sep 17 00:00:00 2001 From: Deepak Chandan Date: Wed, 18 Oct 2023 23:43:10 -0400 Subject: [PATCH] posting items fixes --- STACpopulator/api_requests.py | 6 +++--- STACpopulator/implementations/CMIP6-UofT/add_CMIP6.py | 4 ++-- STACpopulator/populator_base.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/STACpopulator/api_requests.py b/STACpopulator/api_requests.py index fdd9a65..23a7371 100644 --- a/STACpopulator/api_requests.py +++ b/STACpopulator/api_requests.py @@ -2,6 +2,7 @@ import os from typing import Any, Optional from urllib.parse import urljoin + import requests from colorlog import ColoredFormatter @@ -79,17 +80,16 @@ def post_stac_item( """ item_id = json_data["id"] - r = requests.post(urljoin(stac_host, f"collections/{collection_id}/items"), json=json_data) + r = requests.post(os.path.join(stac_host, f"collections/{collection_id}/items"), json=json_data) if r.status_code == 200: LOGGER.info(f"Item {item_name} successfully added") elif r.status_code == 409: if update: LOGGER.info(f"Item {item_id} already exists. Updating.") - r = requests.put(urljoin(stac_host, f"collections/{collection_id}/items/{item_id}"), json=json_data) + r = requests.put(os.path.join(stac_host, f"collections/{collection_id}/items/{item_id}"), json=json_data) r.raise_for_status() else: LOGGER.info(f"Item {item_id} already exists.") else: r.raise_for_status() - diff --git a/STACpopulator/implementations/CMIP6-UofT/add_CMIP6.py b/STACpopulator/implementations/CMIP6-UofT/add_CMIP6.py index a137a0b..3f2f115 100644 --- a/STACpopulator/implementations/CMIP6-UofT/add_CMIP6.py +++ b/STACpopulator/implementations/CMIP6-UofT/add_CMIP6.py @@ -161,8 +161,8 @@ def create_stac_item(self, item_name: str, item_data: MutableMapping[str, Any]) except: LOGGER.warning(f"Failed to add Datacube extension to item {item_name}") - # return json.dumps(item.to_dict()) - print(json.dumps(item.to_dict())) + # print(json.dumps(item.to_dict())) + return json.loads(json.dumps(item.to_dict())) def validate_stac_item_cv(self, data: MutableMapping[str, Any]) -> bool: # Validation is done at the item creating stage, using the Properties class. diff --git a/STACpopulator/populator_base.py b/STACpopulator/populator_base.py index 07841bc..beb1541 100644 --- a/STACpopulator/populator_base.py +++ b/STACpopulator/populator_base.py @@ -124,7 +124,7 @@ def ingest(self) -> None: for item_name, item_data in self._ingest_pipeline: LOGGER.info(f"Creating STAC representation for {item_name}") stac_item = self.create_stac_item(item_name, item_data) - # post_stac_item(self.stac_host, self.collection_id, item_name, stac_item) + post_stac_item(self.stac_host, self.collection_id, item_name, stac_item) # try: # pass # except Exception: