diff --git a/earthaccess/api.py b/earthaccess/api.py index 19391264..a10ee0e2 100644 --- a/earthaccess/api.py +++ b/earthaccess/api.py @@ -6,10 +6,10 @@ from fsspec import AbstractFileSystem from .auth import Auth +from .results import DataGranule from .search import CollectionQuery, DataCollections, DataGranules, GranuleQuery from .store import Store from .utils import _validation as validate -from .results import DataGranule def search_datasets( @@ -152,7 +152,7 @@ def login(strategy: str = "all", persist: bool = False) -> Auth: def download( granules: Union[DataGranule, List[DataGranule], List[str]], - local_path: Optional[str], + local_path: Union[str, None], provider: Optional[str] = None, threads: int = 8, ) -> List[str]: diff --git a/earthaccess/store.py b/earthaccess/store.py index d4e7f181..cfe7bc79 100644 --- a/earthaccess/store.py +++ b/earthaccess/store.py @@ -453,6 +453,12 @@ def get( Returns: List of downloaded files """ + if local_path is None: + local_path = os.path.join( + ".", + "data", + f"{datetime.datetime.today().strftime('%Y-%m-%d')}-{uuid4().hex[:6]}", + ) if len(granules): files = self._get(granules, local_path, provider, threads) return files @@ -464,7 +470,7 @@ def get( def _get( self, granules: Union[List[DataGranule], List[str]], - local_path: Optional[str] = None, + local_path: str, provider: Optional[str] = None, threads: int = 8, ) -> Union[None, List[str]]: @@ -492,7 +498,7 @@ def _get( def _get_urls( self, granules: List[str], - local_path: Optional[str] = None, + local_path: str, provider: Optional[str] = None, threads: int = 8, ) -> Union[None, List[str]]: @@ -523,7 +529,7 @@ def _get_urls( def _get_granules( self, granules: List[DataGranule], - local_path: Optional[str] = None, + local_path: str, provider: Optional[str] = None, threads: int = 8, ) -> Union[None, List[str]]: @@ -599,7 +605,7 @@ def _download_file(self, url: str, directory: str) -> str: return local_path def _download_onprem_granules( - self, urls: List[str], directory: Optional[str] = None, threads: int = 8 + self, urls: List[str], directory: str, threads: int = 8 ) -> List[Any]: """ downloads a list of URLS into the data directory. @@ -616,14 +622,10 @@ def _download_onprem_granules( "We need to be logged into NASA EDL in order to download data granules" ) return [] - if directory is None: - directory_prefix = f"./data/{datetime.datetime.today().strftime('%Y-%m-%d')}-{uuid4().hex[:6]}" - else: - directory_prefix = directory - if not os.path.exists(directory_prefix): - os.makedirs(directory_prefix) + if not os.path.exists(directory): + os.makedirs(directory) - arguments = [(url, directory_prefix) for url in urls] + arguments = [(url, directory) for url in urls] results = pqdm( arguments, self._download_file, diff --git a/tests/integration/test_api.py b/tests/integration/test_api.py index 5736fa50..71745ff5 100644 --- a/tests/integration/test_api.py +++ b/tests/integration/test_api.py @@ -1,7 +1,6 @@ # package imports import logging import os -import shutil import unittest import earthaccess