You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""redirect-diff: compare old vs new sitemap (URL or file) and list old paths with no new equivalent. stdlib only."""
import sys, re, urllib.request, urllib.parse
def load(s):
d=urllib.request.urlopen(urllib.request.Request(s,headers={"User-Agent":"redirect-diff/1.0"}),timeout=30).read().decode() if s.startswith("http") else open(s).read()
locs=re.findall(r"<loc>\s*([^<]+?)\s*</loc>",d) or [l.strip() for l in d.splitlines() if l.strip()]
return {urllib.parse.urlparse(u).path.rstrip("/") or "/" for u in locs}
print(f"old={len(old)} new={len(new)} unmatched old paths={len(gone)}")
for p in gone[:200]: print(" ", p)
q=("old="+urllib.parse.quote(sys.argv[1],safe="")+"&new="+urllib.parse.quote(sys.argv[2],safe="")+"&") if all(x.startswith("https://") for x in sys.argv[1:3]) else ""
if gone: print("\nThese need 301s or they 404 after launch. Host-ready redirect map (free check first): https://routepatch.adjudi.com/?"+q+"utm_source=github&utm_medium=cli&utm_campaign=routepatch-intent-w2&utm_content=redirect-diff")
sys.exit(1 if gone and "--fail" in sys.argv else 0)