error fix
This commit is contained in:
+23
-13
@@ -7,42 +7,52 @@ import sys
|
||||
|
||||
|
||||
def main():
|
||||
raw_json = os.environ.get("OPTIONS_B64_JSON", "[]").strip()
|
||||
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_json)
|
||||
options_b64 = json.loads(raw_options)
|
||||
except json.JSONDecodeError as exc:
|
||||
print(f"FEHLER: OPTIONS_B64_JSON ist kein gültiges JSON: {exc}", file=sys.stderr)
|
||||
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 raw in options_b64:
|
||||
if not raw:
|
||||
continue
|
||||
|
||||
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")
|
||||
options.extend(json.loads(decoded))
|
||||
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: Ein Host-Ergebnis konnte nicht gelesen werden: {exc}", file=sys.stderr)
|
||||
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 f:
|
||||
json.dump(options, f, indent=2, ensure_ascii=False)
|
||||
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("Dropdown-Liste:")
|
||||
print(json.dumps(options, indent=2, ensure_ascii=False))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user