Skip to content

Commit

Permalink
implement get_urls(type_="s3")
Browse files Browse the repository at this point in the history
  • Loading branch information
scottstanie committed Sep 30, 2024
1 parent b1f956a commit 3c0ccab
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/opera_utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,20 +296,26 @@ def filter_results_by_date_and_version(results: ASFSearchResults) -> ASFSearchRe
def _get_urls(
results: asf.ASFSearchResults,
type_: Literal["https", "s3"] = "https",
file_ext: str = ".h5",
) -> list[str]:
if type_ == "https":
return [r.properties["url"] for r in results]
elif type_ == "s3":
# TODO: go through .umm, find s3 url
raise NotImplementedError()
out: list[str] = []
for r in results:
if "s3Urls" not in r.properties:
raise ValueError(f"No S3 URL for {r}")

for url in r.properties["s3Urls"]:
if url.endswith(file_ext):
out.append(url)
break
else:
raise ValueError(f"Failed to find HDF5 S3 url for {r}")
return out

else:
raise ValueError(f"type_ must be 'https' or 's3'. Got {type_}")
# r.umm
# 'RelatedUrls': [...
# {'URL': 's3://asf-cumulus-prod-opera-products/OPERA_L2_CSLC
# 'Type': 'GET DATA VIA DIRECT ACCESS',
# 'Description': 'This link provides direct download access vi
# 'Format': 'HDF5'},


def _get_auth_session() -> asf.ASFSession:
Expand Down

0 comments on commit 3c0ccab

Please sign in to comment.