From c24bbf740dd7f6462646306a32c7197980695c67 Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Tue, 22 Oct 2024 16:08:36 +0200 Subject: [PATCH] refactor get_url_size --- src/zampy/datasets/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/zampy/datasets/utils.py b/src/zampy/datasets/utils.py index a737baa..1e3a237 100644 --- a/src/zampy/datasets/utils.py +++ b/src/zampy/datasets/utils.py @@ -43,10 +43,13 @@ def download_url(url: str, fpath: Path, overwrite: bool) -> None: print(f"File '{fpath.name}' already exists, skipping...") -def get_url_size(url: str) -> int: +def get_url_size(url: str) -> int | None: """Return the size (bytes) of a given URL.""" response = requests.head(url) - return int(response.headers["Content-Length"]) + content_length = response.headers.get("Content-Length") + if content_length: + return int(content_length) + return None def get_file_size(fpath: Path) -> int: