Skip to content

Instantly share code, notes, and snippets.

@nottrobin
Created May 15, 2019 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nottrobin/dd9b5c2084ea22c802fd1cdeb1a12b86 to your computer and use it in GitHub Desktop.
Save nottrobin/dd9b5c2084ea22c802fd1cdeb1a12b86 to your computer and use it in GitHub Desktop.
Get target URLs from a redirect mapping
#! /usr/bin/env python3
import requests
from urllib.parse import urlparse
import yaml
for path, location in yaml.load(open("redirect-source.yaml")).items():
response = requests.get(f"http://docs.snapcraft.io{location}")
if response.ok:
target_path = urlparse(response.url).path
print(f"{path}: {target_path}")
else:
print(response, path, response.url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment