Skip to content

Commit c4aaa3e

Browse files
authored
feat: add option to parse downloading stac from file (#134)
* feat: add option to parse downloading stac from file * fix: version increment error + update change log
1 parent 961604d commit c4aaa3e

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.3.0] - 2023-01-23
9+
### Added
10+
- [#134](https://github.com/unity-sds/unity-data-services/pull/134) feat: add option to parse downloading stac from file
11+
812
## [3.2.0] - 2023-01-23
913
### Added
1014
- [#131](https://github.com/unity-sds/unity-data-services/pull/131) granules query pagination

cumulus_lambda_functions/stage_in_out/download_granules_s3.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,25 @@ def __init__(self) -> None:
1919
self.__s3 = AwsS3()
2020
self.__granules_json = []
2121

22+
def __retrieve_stac_json(self):
23+
raw_stac_json = os.environ.get(self.STAC_JSON)
24+
try:
25+
self.__granules_json = json.loads(raw_stac_json)
26+
return self
27+
except:
28+
LOGGER.debug(f'raw_stac_json is not STAC_JSON: {raw_stac_json}. trying to see if file exists')
29+
if not FileUtils.file_exist(raw_stac_json):
30+
raise ValueError(f'missing file or not JSON: {raw_stac_json}')
31+
self.__granules_json = FileUtils.read_json(raw_stac_json)
32+
if self.__granules_json is None:
33+
raise ValueError(f'{raw_stac_json} is not JSON')
34+
return self
35+
2236
def __set_props_from_env(self):
2337
missing_keys = [k for k in [self.STAC_JSON, self.DOWNLOAD_DIR_KEY] if k not in os.environ]
2438
if len(missing_keys) > 0:
2539
raise ValueError(f'missing environment keys: {missing_keys}')
26-
self.__granules_json = json.loads(os.environ.get(self.STAC_JSON))
40+
self.__retrieve_stac_json()
2741
self.__download_dir = os.environ.get(self.DOWNLOAD_DIR_KEY)
2842
self.__download_dir = self.__download_dir[:-1] if self.__download_dir.endswith('/') else self.__download_dir
2943
return self

0 commit comments

Comments
 (0)