Skip to content

Commit

Permalink
refactor(download): Move to pathlib
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Jun 12, 2023
1 parent 177c2f9 commit 5bbff7a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/unihan_etl/process.py
Expand Up @@ -301,16 +301,18 @@ def download(
pathlib.Path :
destination where file downloaded to.
"""
if not isinstance(dest, pathlib.Path):
dest = pathlib.Path(dest)

data_dir = os.path.dirname(dest)
if not os.path.exists(data_dir):
os.makedirs(data_dir)
data_dir = dest.parent
if not data_dir.exists():
data_dir.mkdir(parents=True, exist_ok=True)

def no_unihan_files_exist() -> bool:
return not glob.glob(os.path.join(data_dir, "Unihan*.txt"))
return not data_dir.match("Unihan*.txt")

def not_downloaded() -> bool:
return not os.path.exists(os.path.join(data_dir, "Unihan.zip"))
return not (data_dir / "Unihan.zip").exists()

if (no_unihan_files_exist() and not_downloaded()) or not cache:
log.info("Downloading Unihan.zip...")
Expand Down

0 comments on commit 5bbff7a

Please sign in to comment.