Skip to content

Instantly share code, notes, and snippets.

@jsonbecker
Created February 19, 2014 15:40
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 jsonbecker/9094588 to your computer and use it in GitHub Desktop.
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.
#!/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