Skip to content

Commit

Permalink
posting items fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dchandan committed Oct 19, 2023
1 parent 8d66fba commit 00a968a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions STACpopulator/api_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from typing import Any, Optional
from urllib.parse import urljoin

import requests
from colorlog import ColoredFormatter

Expand Down Expand Up @@ -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()

4 changes: 2 additions & 2 deletions STACpopulator/implementations/CMIP6-UofT/add_CMIP6.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion STACpopulator/populator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 00a968a

Please sign in to comment.