diff --git a/earthaccess/store.py b/earthaccess/store.py index 44853918..15ae4ef2 100644 --- a/earthaccess/store.py +++ b/earthaccess/store.py @@ -442,7 +442,7 @@ def _open_urls( def get( self, granules: Union[List[DataGranule], List[str]], - local_path: Optional[str] = None, + local_path: Optional[Path] = None, provider: Optional[str] = None, threads: int = 8, ) -> List[str]: @@ -465,11 +465,10 @@ def get( List of downloaded files """ if local_path is None: - local_path = Path( - ".", - "data", - f"{datetime.datetime.today().strftime('%Y-%m-%d')}-{uuid4().hex[:6]}", - ) + today = datetime.datetime.today().strftime("%Y-%m-%d") + uuid = uuid4().hex[:6] + local_path = Path.cwd() / "data" / f"{today}-{uuid}" + if len(granules): files = self._get(granules, local_path, provider, threads) return files @@ -578,9 +577,9 @@ def _get_granules( else: # if the data are cloud-based, but we are not in AWS, # it will be downloaded as if it was on prem - return self._download_onprem_granules(data_links, str(local_path), threads) + return self._download_onprem_granules(data_links, local_path, threads) - def _download_file(self, url: str, directory: str) -> str: + def _download_file(self, url: str, directory: Path) -> str: """Download a single file from an on-prem location, a DAAC data center. Parameters: @@ -594,7 +593,7 @@ def _download_file(self, url: str, directory: str) -> str: if "opendap" in url and url.endswith(".html"): url = url.replace(".html", "") local_filename = url.split("/")[-1] - path = Path(directory) / Path(local_filename) + path = directory / Path(local_filename) if not path.exists(): try: session = self.auth.get_session() @@ -617,7 +616,7 @@ def _download_file(self, url: str, directory: str) -> str: return str(path) def _download_onprem_granules( - self, urls: List[str], directory: str, threads: int = 8 + self, urls: List[str], directory: Path, threads: int = 8 ) -> List[Any]: """Downloads a list of URLS into the data directory. @@ -636,7 +635,7 @@ def _download_onprem_granules( raise ValueError( "We need to be logged into NASA EDL in order to download data granules" ) - Path(directory).mkdir(parents=True, exist_ok=True) + directory.mkdir(parents=True, exist_ok=True) arguments = [(url, directory) for url in urls] results = pqdm(