Mercurial > hg > orthanc
diff OrthancServer/Resources/GenerateAnonymizationProfile.py @ 4675:7e4d1f2b3a8f
GenerateAnonymizationProfile.py can read from URL
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 03 Jun 2021 19:41:11 +0200 |
parents | d9473bd5ed43 |
children | caf963ee3de9 |
line wrap: on
line diff
--- a/OrthancServer/Resources/GenerateAnonymizationProfile.py Thu Jun 03 17:40:15 2021 +0200 +++ b/OrthancServer/Resources/GenerateAnonymizationProfile.py Thu Jun 03 19:41:11 2021 +0200 @@ -32,17 +32,26 @@ import re +import requests import sys import xml.etree.ElementTree as ET # Usage: -# ./GenerateAnonymizationProfile.py ~/Subversion/dicom-specification/2017c/part15.xml +# ./GenerateAnonymizationProfile.py https://raw.githubusercontent.com/jodogne/dicom-specification/master/2021b/part15.xml if len(sys.argv) != 2: - raise Exception('Please provide the path to the part15.xml file from the DICOM standard') + raise Exception('Please provide the path or the URL to the part15.xml file from the DICOM standard') + +source = sys.argv[1] -with open(sys.argv[1], 'r') as f: - root = ET.fromstring(f.read()) +if (source.startswith('http://') or + source.startswith('https://')): + part15 = requests.get(source).content +else: + with open(source, 'r') as f: + part15 = f.read() + +root = ET.fromstring(part15) br = '{http://docbook.org/ns/docbook}' # Shorthand variable @@ -115,7 +124,7 @@ FormatUnknown(rawTag, name, profile) for line in sorted(LINES): - print line + print(line.encode('ascii', 'ignore').decode('ascii')) # D - replace with a non-zero length value that may be a dummy value and consistent with the VR