61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import base64
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
|
|
def main():
|
|
raw_options = os.environ.get("OPTIONS_B64_JSON", "").strip()
|
|
|
|
if not raw_options:
|
|
print("FEHLER: OPTIONS_B64_JSON ist leer", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
try:
|
|
options_b64 = json.loads(raw_options)
|
|
except json.JSONDecodeError as exc:
|
|
print("FEHLER: OPTIONS_B64_JSON ist kein gültiges JSON", file=sys.stderr)
|
|
print(str(exc), file=sys.stderr)
|
|
print("Rohwert:", raw_options, file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
options = []
|
|
|
|
for index, raw in enumerate(options_b64, start=1):
|
|
raw = str(raw).strip()
|
|
|
|
if not raw:
|
|
print(f"WARNUNG: Host-Ergebnis {index} ist leer")
|
|
continue
|
|
|
|
try:
|
|
decoded = base64.b64decode(raw).decode("utf-8")
|
|
decoded_options = json.loads(decoded)
|
|
|
|
if not isinstance(decoded_options, list):
|
|
print(f"WARNUNG: Host-Ergebnis {index} ist keine JSON-Liste")
|
|
continue
|
|
|
|
options.extend(decoded_options)
|
|
|
|
except Exception as exc:
|
|
print(f"WARNUNG: Host-Ergebnis {index} konnte nicht verarbeitet werden: {exc}", file=sys.stderr)
|
|
|
|
options = sorted(set(options))
|
|
|
|
with open("select_options.json", "w", encoding="utf-8") as file:
|
|
json.dump(options, file, indent=2, ensure_ascii=False)
|
|
|
|
print("==========================================")
|
|
print("Dropdown-Liste gebaut")
|
|
print(f"Dropdown-Optionen: {len(options)}")
|
|
print("==========================================")
|
|
print("")
|
|
print(json.dumps(options, indent=2, ensure_ascii=False))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|