Skip to content

Instantly share code, notes, and snippets.

@foota
Created May 14, 2012 17:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foota/2695187 to your computer and use it in GitHub Desktop.
Save foota/2695187 to your computer and use it in GitHub Desktop.
goo.gl URL shortener
import sys,re
from urllib2 import urlopen as U, Request as R
from json import loads as J
API,URL="https://www.googleapis.com/urlshortener/v1/url",sys.argv[1]
if re.match('http://goo\.gl/.+',URL):print J(U(API+'?shortUrl=%s'%URL).read())['longUrl']
else:print J(U(R(API,'{"longUrl":"%s"}'%URL,{'Content-Type':'application/json'})).read())['id']
@foota
Copy link
Author

foota commented May 14, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment