import json import re with open("scratch/unified_docs_data.json") as f: data = json.load(f) # Helper to build clean URL def clean_full_url(base_link, subpath, original_path): base_link = base_link.rstrip("/") subpath = subpath.strip("/") # If base_link ends with the first segment of subpath, avoid duplicating base_parts = base_link.split("/") sub_parts = subpath.split("/") # Check if last part of base_parts matches first part of sub_parts if len(sub_parts) > 1 and base_parts[-1] == sub_parts[0]: return base_link + "/" + "/".join(sub_parts[1:]) + "/" # Check if subpath is already in base_link if subpath == "image" or subpath == "image/": return base_link + "/image/" if subpath == "analyze": return base_link + "/analyze" if subpath == "get_eye_mask": return base_link + "/get_eye_mask" return base_link + "/" + subpath + ("/" if not subpath.endswith("/") and "." not in subpath else "") # Inspect all URLs for s in data["sections"]: for a in s["apis"]: base_link = a["api_ip_link"] for ep in a["endpoints"]: orig = ep["full_url"] fixed = clean_full_url(base_link, ep["subpath"], ep["path"]) ep["full_url"] = fixed print(f"[{a['api_key']}] {ep['subpath']} -> {fixed}") with open("scratch/unified_docs_data.json", "w") as f: json.dump(data, f, indent=2) print("\nDone fixing URLs!")