Created
April 12, 2013 22:09
-
-
Save sassman/5375560 to your computer and use it in GitHub Desktop.
a small tiny cli wrapper to goole url shortener api
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 json, sys, urllib2 | |
url = sys.argv[1] | |
apiKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX' | |
data = { | |
'longUrl' : url | |
} | |
req = urllib2.Request('https://www.googleapis.com/urlshortener/v1/url?key='+apiKey) | |
req.add_header('Content-Type', 'application/json') | |
response = json.loads(urllib2.urlopen(req, json.dumps(data)).read()) | |
print response['id'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment