Created
May 15, 2019 09:50
-
-
Save nottrobin/dd9b5c2084ea22c802fd1cdeb1a12b86 to your computer and use it in GitHub Desktop.
Get target URLs from a redirect mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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