diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index b1b043e..8f66fe9 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -1,6 +1,10 @@ Changelog ========= +Version 2.18 +------------ +* Download URL computation has its own method + Version 2.17 ----------- * Added Conda-Forge repository diff --git a/docs/source/conf.py b/docs/source/conf.py index 8e76962..f9c8471 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -15,8 +15,8 @@ copyright = "2023, ECMWF" author = "ECMWF" -release = "2.17" -version = "2.17" +release = "2.18" +version = "2.18" # -- General configuration diff --git a/hda/api.py b/hda/api.py index 4835f4a..973c651 100644 --- a/hda/api.py +++ b/hda/api.py @@ -269,19 +269,38 @@ def __getitem__(self, index): def _download(self, result, download_dir: str = "."): logger.debug(result) self.client.accept_tac(self.dataset) + download_id = self._get_download_id(result) + self.stream( + download_id, + result["properties"]["size"], + download_dir, + ) + def _get_download_id(self, result): query = { "dataset_id": self.dataset, "product_id": result["id"], "location": result["properties"]["location"], } - download_id = DataOrderRequest(self.client).run(query) + return DataOrderRequest(self.client).run(query) - self.stream( - download_id, - result["properties"]["size"], - download_dir, - ) + def get_download_urls(self, limit: int = None): + """Utility function to return the list of final download URLs. + Useful in the context of the Serverless Functions service. + If the list of results is long, it might take a long time. + In that case, either subset the results or set a value for `limit`. + """ + + def build_url(result): + download_id = self._get_download_id(result) + return self.client.full_url(*[f"dataaccess/download/{download_id}"]) + + if limit is not None: + results = self.results[:limit] + else: + results = self.results + + return [build_url(r) for r in results] def download(self, download_dir: str = "."): """Downloads the results into the given download directory. diff --git a/setup.py b/setup.py index 294c698..310381d 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ def read(fname): return io.open(file_path, encoding="utf-8").read() -version = "2.17" +version = "2.18" setuptools.setup( name="hda",