Skip to content

Commit

Permalink
bypass find limit for downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
bcrickboom committed Aug 12, 2024
1 parent 90ca104 commit 73901f4
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions orthanc_tools/orthanc_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,20 @@
retry_count = 0
retry_delays = [5, 20, 60, 300, 900]

studies = []
studies_ids = []
while retry_count < 5:
if retry_count >= 1:
delay = retry_delays[retry_count - 1]
logger.info(f"waiting {delay} seconds before retrying get studies ids")
time.sleep(delay)
try:
logger.info(f"Getting list of studies ids...")
studies = o.studies.find(query={}, labels=labels)
# workaround to avoid find results limit
all_ids = o.studies.get_all_ids()
for id in all_ids:
study_labels = o.studies.get_labels(id)
if any(element in study_labels for element in labels):
studies_ids.append(id)
break
except Exception as ex:
retry_count += 1
Expand All @@ -58,14 +63,15 @@
logger.warning(f"Error while getting studies ids, retrying... Ex:{str(ex)}")

progress_counter = 1
for study in studies:
for id in studies_ids:
try:
logger.info(f"Downloading study {progress_counter} out of {len(studies)}")
folder_path = args.folder + study.orthanc_id
logger.info(f"Downloading study {progress_counter} out of {len(studies_ids)}")
folder_path = args.folder + id
os.mkdir(folder_path)
o.studies.download_instances(study_id=study.orthanc_id, path=folder_path)
o.studies.download_instances(study_id=id, path=folder_path)
progress_counter += 1
except Exception as ex:
logger.error(f"Error during download for study {study.orthanc_id}. Ex: {str(ex)}")
logger.error(f"Error during download for study {id}. Ex: {str(ex)}")
sys.exit(1)

logger.info("Over :-)")

0 comments on commit 73901f4

Please sign in to comment.