SHARE
TWEET

Untitled

a guest Dec 5th, 2011 592 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top