Created
February 19, 2014 15:40
-
-
Save jsonbecker/9094588 to your computer and use it in GitHub Desktop.
A quick way to clean up an URL, removing common tracking and getting around proxy links to get the proper permanent link.
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/python | |
import requests | |
import sys | |
from re import search | |
from subprocess import check_output | |
url = check_output('pbpaste') | |
r = requests.get(url) | |
#Need to remove some cases with &utm_source | |
match = search(r'[?&#]utm_', r.url) | |
# Because I'm not smart and trigger this with | |
# already clean URLs | |
if match: | |
cleanURL = r.url.split(match.group())[0] | |
else: | |
cleanURL = r.url | |
print cleanURL | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment