Skip to content

Commit

Permalink
added check to see if files is already downloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
annajungbluth committed Jul 3, 2024
1 parent 4049235 commit 1eb8f55
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions rs_tools/_src/data/msg/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1eb8f55

Please sign in to comment.