"""Liest TrassenOrder User Research von SAB Confluence.""" import urllib.request, json, ssl, re secrets = {} with open("project-audit/.secrets", "r", encoding="utf-8-sig") as f: for line in f: if "=" in line and not line.startswith("#"): k, v = line.strip().split("=", 1) secrets[k.strip()] = v.strip() ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE CONF_TOKEN = secrets.get("CONFLUENCE_SAB", "") CONF_URL = "https://systelone-confluence.jaas.service.deutschebahn.com/rest/api" PAGE_ID = "85858484" print(f"Token: ...{CONF_TOKEN[-4:]}") print(f"URL: {CONF_URL}/content/{PAGE_ID}") print() try: req = urllib.request.Request(f"{CONF_URL}/content/{PAGE_ID}?expand=body.storage") req.add_header("Authorization", f"Bearer {CONF_TOKEN}") resp = urllib.request.urlopen(req, context=ctx, timeout=30) data = json.loads(resp.read().decode("utf-8")) title = data.get("title", "?") body = data["body"]["storage"]["value"] print(f"Titel: {title}") # HTML zu Text text = re.sub(r'<[^>]+>', '\n', body) text = re.sub(r'\n{3,}', '\n\n', text).strip() print(f"Laenge: {len(text)} Zeichen") print() print(text[:5000]) # Speichern with open("project-audit/data/trapo-user-research.txt", "w", encoding="utf-8") as f: f.write(text) print(f"\n\nGespeichert: project-audit/data/trapo-user-research.txt ({len(text)} Zeichen)") except Exception as e: print(f"Fehler: {e}")