Mercurial > hg > orthanc
diff Resources/Samples/Python/ArchiveStudiesInTimeRange.py @ 2070:7e6afa0beaf6
samples: improved handling of special characters in paths
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 14 Jul 2016 09:05:22 +0200 |
parents | 65b1ce7cb84f |
children | a3a65de1840f |
line wrap: on
line diff
--- a/Resources/Samples/Python/ArchiveStudiesInTimeRange.py Wed Jul 13 16:52:39 2016 +0200 +++ b/Resources/Samples/Python/ArchiveStudiesInTimeRange.py Thu Jul 14 09:05:22 2016 +0200 @@ -49,6 +49,12 @@ CheckIsDate(START) CheckIsDate(END) +def GetTag(tags, key): + if key in tags: + return tags[key] + else: + return 'No%s' % key + # Loop over the studies for studyId in RestToolbox.DoGet('%s/studies' % URL): # Retrieve the DICOM tags of the current study @@ -61,13 +67,13 @@ studyDate = study['StudyDate'][:8] if studyDate >= START and studyDate <= END: # Create a filename - filename = '%s - %s %s - %s.zip' % (study['StudyDate'], - patient['PatientID'], - patient['PatientName'], - study['StudyDescription']) + filename = '%s - %s %s - %s.zip' % (GetTag(study, 'StudyDate'), + GetTag(patient, 'PatientID'), + GetTag(patient, 'PatientName'), + GetTag(study, 'StudyDescription')) # Remove any non-ASCII character in the filename - filename = filename.encode('ascii', errors = 'replace') + filename = filename.encode('ascii', errors = 'replace').translate(None, r"'\/:*?\"<>|!=").strip() # Download the ZIP archive of the study print('Downloading %s' % filename)