From e541c4b0978eea9e7efdd9570fdd81ab7cf88104 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Mon, 15 Jul 2024 07:35:58 -0400 Subject: [PATCH] Remove wget (#151) --- learning_observer/learning_observer/prestartup.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/learning_observer/learning_observer/prestartup.py b/learning_observer/learning_observer/prestartup.py index 2ec16b00..54debdb1 100644 --- a/learning_observer/learning_observer/prestartup.py +++ b/learning_observer/learning_observer/prestartup.py @@ -13,6 +13,7 @@ import hashlib import os import os.path +import requests import shutil import sys import uuid @@ -147,10 +148,16 @@ def format_hash(hash_string): # For subdirectories, make them os.makedirs(os.path.dirname(filename), exist_ok=True) if not os.path.exists(filename): - os.system("wget {url} -O {filename} 2> /dev/null".format( - url=url, - filename=filename - )) + # TODO: For larger downloads, we might want to set + # stream=True and use iter_content instead + response = requests.get(url) + if response.status_code == 200: + with open(filename, 'wb') as file: + file.write(response.content) + print("Downloaded {name}".format(name=name)) + else: + print("Failed to download file") + print("Downloaded {name}".format(name=name)) shahash = hashlib.sha3_512(open(filename, "rb").read()).hexdigest() if shahash not in hashes: