Skip to content

Commit b036811

Browse files
committed
a little path vs str cleanup
1 parent c68e634 commit b036811

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

earthaccess/store.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def _open_urls(
442442
def get(
443443
self,
444444
granules: Union[List[DataGranule], List[str]],
445-
local_path: Optional[str] = None,
445+
local_path: Optional[Path] = None,
446446
provider: Optional[str] = None,
447447
threads: int = 8,
448448
) -> List[str]:
@@ -465,11 +465,10 @@ def get(
465465
List of downloaded files
466466
"""
467467
if local_path is None:
468-
local_path = Path(
469-
".",
470-
"data",
471-
f"{datetime.datetime.today().strftime('%Y-%m-%d')}-{uuid4().hex[:6]}",
472-
)
468+
today = datetime.datetime.today().strftime("%Y-%m-%d")
469+
uuid = uuid4().hex[:6]
470+
local_path = Path.cwd() / "data" / f"{today}-{uuid}"
471+
473472
if len(granules):
474473
files = self._get(granules, local_path, provider, threads)
475474
return files
@@ -578,9 +577,9 @@ def _get_granules(
578577
else:
579578
# if the data are cloud-based, but we are not in AWS,
580579
# it will be downloaded as if it was on prem
581-
return self._download_onprem_granules(data_links, str(local_path), threads)
580+
return self._download_onprem_granules(data_links, local_path, threads)
582581

583-
def _download_file(self, url: str, directory: str) -> str:
582+
def _download_file(self, url: str, directory: Path) -> str:
584583
"""Download a single file from an on-prem location, a DAAC data center.
585584
586585
Parameters:
@@ -594,7 +593,7 @@ def _download_file(self, url: str, directory: str) -> str:
594593
if "opendap" in url and url.endswith(".html"):
595594
url = url.replace(".html", "")
596595
local_filename = url.split("/")[-1]
597-
path = Path(directory) / Path(local_filename)
596+
path = directory / Path(local_filename)
598597
if not path.exists():
599598
try:
600599
session = self.auth.get_session()
@@ -617,7 +616,7 @@ def _download_file(self, url: str, directory: str) -> str:
617616
return str(path)
618617

619618
def _download_onprem_granules(
620-
self, urls: List[str], directory: str, threads: int = 8
619+
self, urls: List[str], directory: Path, threads: int = 8
621620
) -> List[Any]:
622621
"""Downloads a list of URLS into the data directory.
623622
@@ -636,7 +635,7 @@ def _download_onprem_granules(
636635
raise ValueError(
637636
"We need to be logged into NASA EDL in order to download data granules"
638637
)
639-
Path(directory).mkdir(parents=True, exist_ok=True)
638+
directory.mkdir(parents=True, exist_ok=True)
640639

641640
arguments = [(url, directory) for url in urls]
642641
results = pqdm(

0 commit comments

Comments
 (0)