Created
April 1, 2011 21:08
-
-
Save bmc/898862 to your computer and use it in GitHub Desktop.
Access goo.gl from Python
This file contains hidden or 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
# Test of Goo.gl Python front-end available at | |
# http://code.google.com/p/python-googl/source/checkout | |
# | |
# Some kind of JSON parser must be installed. 'simplejson' works fine. | |
# | |
# See | |
# http://code.google.com/apis/urlshortener/v1/getting_started.html#shorten | |
# for Goo.gl API info. | |
import googl | |
if __name__ == '__main__': | |
import sys | |
# NOTE: Constructor DOES support an API key, which the Google | |
# documentation (see above) recommends. | |
g = googl.Googl() | |
for url in sys.argv[1:]: | |
# returns a hash | |
hash = g.shorten(url) | |
shortened = hash['id'] | |
print('%s -> %s' % (url, shortened)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment