File indexing completed on 2024-11-24 04:44:41
0001 #!/usr/bin/env python3 0002 # SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> 0003 # SPDX-License-Identifier: LGPL-2.0-or-later 0004 0005 import value_sets_pb2 0006 0007 import argparse 0008 import datetime 0009 import io 0010 import json 0011 import os 0012 import requests 0013 import zipfile 0014 0015 value_sets = {} 0016 0017 def downloadValueSets(lang): 0018 valueSetsFile = f"value_sets_{lang}.zip" 0019 req = requests.get(f"https://svc90.main.px.t-online.de/version/v1/ehn-dgc/{lang}/value-sets") 0020 f = open(valueSetsFile, 'wb') 0021 f.write(req.content) 0022 f.close() 0023 0024 zipFile = zipfile.ZipFile(valueSetsFile, 'r') 0025 binData = zipFile.read('export.bin') 0026 0027 valueSets = value_sets_pb2.ValueSets() 0028 valueSets.ParseFromString(binData) 0029 0030 for category in ['tg', 'vp', 'ma', 'mp', 'tcTt', 'tcMa', 'tcTr']: 0031 if not category in value_sets: 0032 value_sets[category] = {} 0033 stringMapping = getattr(valueSets, category) 0034 for entry in stringMapping.items: 0035 if lang == 'en': 0036 value_sets[category][entry.key] = entry.displayText; 0037 # only add translations if they actually differ 0038 elif value_sets[category][entry.key] != entry.displayText: 0039 value_sets[category][f"{entry.key}[{lang}]"] = entry.displayText; 0040 0041 0042 parser = argparse.ArgumentParser(description='Download and merge translations for codes used in EU DGCs') 0043 parser.add_argument('--output', type=str, required=True, help='Path to which the output should be written to') 0044 arguments = parser.parse_args() 0045 0046 # keep en first 0047 for lang in ['en', 'de']: 0048 downloadValueSets(lang) 0049 0050 for key in value_sets: 0051 f = open(os.path.join(arguments.output, f"{key}.json"), 'w') 0052 f.write(json.dumps(value_sets[key])) 0053 f.close()