Advertisement
Guest User

Untitled

a guest
Dec 5th, 2011
1,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. #!/usr/bin/env python2
  2.  
  3. #Name          : URL Shortener | url.py
  4. #Version       : 0.1
  5. #Writer(s)     : Alex Long
  6. #Description   : A simple url shortener that uses the Google API. It takes a command line argument to
  7. # quickly shorten URLs
  8. #Notes         : None.
  9.  
  10. import json
  11. import urllib
  12. import urllib2
  13. import sys
  14.  
  15. def main(url):
  16.     gurl = 'http://goo.gl/api/url?url=%s' % urllib.quote(url)
  17.     req = urllib2.Request(gurl, data='')
  18.     req.add_header('User-Agent', 'toolbar')
  19.     results = json.load(urllib2.urlopen(req))
  20.     return results['short_url']
  21.  
  22. if __name__=='__main__':
  23.     print main(sys.argv[1])
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement