From 8fc1bf95729d44c3bb25cf8e1ffc7062bfa04038 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Tue, 2 Nov 2021 15:30:13 -0600 Subject: [PATCH] Clean downloader_file funtion --- resources/utilities.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/resources/utilities.py b/resources/utilities.py index 6f5fce1ae..c2dfe01cc 100644 --- a/resources/utilities.py +++ b/resources/utilities.py @@ -294,16 +294,22 @@ def download_file(link, location): if Path(location).exists(): Path(location).unlink() response = requests.get(link, stream=True) + short_link = os.path.basename(link) + # SU Catalog's link is quite long, strip to make it bearable + if "sucatalog.gz" in short_link: + short_link = "sucatalog.gz" + header = f"# Downloading: {short_link} #" + box_length = len(header) with location.open("wb") as file: count = 0 for chunk in response.iter_content(1024 * 1024 * 4): file.write(chunk) count += len(chunk) cls() - print("####################") - print("# Downloading file #") - print("####################") - print(link) + print("#" * box_length) + print(header) + print("#" * box_length) + print("") print(f"{count / 1024 / 1024}MB Downloaded") checksum = hashlib.sha256() with location.open("rb") as file: