Source code for tempor.models.clairvoyance2.datasets.download
# mypy: ignore-errorsimportosimportshutilimporturllib.request# TODO: Unit test.
[docs]defdownload_file(url:str,file_path:str):print(f"Downloading file from URL: {url}")file_dir,file_name=os.path.split(file_path)iffile_name=="":raiseValueError(f"`file_path` must include a file name, was: {file_path}")ifnotos.path.exists(file_dir):os.makedirs(file_dir,exist_ok=True)# May raise exception, but that's fine.withurllib.request.urlopen(url)asresponse,open(file_path,"wb")asout_file:shutil.copyfileobj(response,out_file)