Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- #Name : URL Shortener | url.py
- #Version : 0.1
- #Writer(s) : Alex Long
- #Description : A simple url shortener that uses the Google API. It takes a command line argument to
- # quickly shorten URLs
- #Notes : None.
- import json
- import urllib
- import urllib2
- import sys
- def main(url):
- gurl = 'http://goo.gl/api/url?url=%s' % urllib.quote(url)
- req = urllib2.Request(gurl, data='')
- req.add_header('User-Agent', 'toolbar')
- results = json.load(urllib2.urlopen(req))
- return results['short_url']
- if __name__=='__main__':
- print main(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement