From 1eb8f55968a5400e528d42f3a588f9257ca2e382 Mon Sep 17 00:00:00 2001 From: annajungbluth Date: Wed, 3 Jul 2024 20:05:56 +0000 Subject: [PATCH] added check to see if files is already downloaded --- rs_tools/_src/data/msg/download.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/rs_tools/_src/data/msg/download.py b/rs_tools/_src/data/msg/download.py index ce4f7be..ef1262a 100644 --- a/rs_tools/_src/data/msg/download.py +++ b/rs_tools/_src/data/msg/download.py @@ -169,10 +169,15 @@ def _msg_data_download(products, save_dir: str): with product.open(entry=entry) as fsrc: # Create a full file path for saving the file save_path = os.path.join(save_dir, os.path.basename(fsrc.name)) - with open(save_path, mode='wb') as fdst: - shutil.copyfileobj(fsrc, fdst) - print(f"Successfully downloaded {entry}.") - return [save_path] + # Check if file already exists + if os.path.exists(save_path): + print(f"File {save_path} already exists. Skipping download.") + return [save_path] + else: + with open(save_path, mode='wb') as fdst: + shutil.copyfileobj(fsrc, fdst) + print(f"Successfully downloaded {entry}.") + return [save_path] except Exception as error: print(f"Error downloading product': '{error}'") pass