@@ -0,0 +1,2063 @@
+import json%0Aimport requests%0Aimport argparse%0Aimport sys%0A%0A%0Aclass GUrlShorten():%0A    def __init__(self, key):%0A        self.API_KEY = key%0A%0A    def google_url_shorten(self, url):%0A        req_url = 'https://www.googleapis.com/urlshortener/v1/url?key=' + self.API_KEY%0A        payload = %7B'longUrl': url%7D%0A        headers = %7B'content-type': 'application/json'%7D%0A        r = requests.post(req_url, json=payload, headers=headers)%0A        resp = json.loads(r.text)%0A        return resp%5B'id'%5D%0A%0A    def google_url_expand(self, url):%0A        req_url = 'https://www.googleapis.com/urlshortener/v1/url'%0A        payload = %7B'key': self.API_KEY, 'shortUrl': url%7D%0A        r = requests.get(req_url, params=payload)%0A        resp = json.loads(r.text)%0A        return resp%5B'longUrl'%5D%0A%0A%0Adef main():%0A    desc = %22A python script to shorten or expand urls using Google Url Shortener API%22%0A%0A    parser = argparse.ArgumentParser(description=desc, prog='GoogleUrlShortener.py')%0A    parser.add_argument('-e', '--expand', action='store_true', help='Short Url will be expanded.')%0A    parser.add_argument('-s', '--shorten', action='store_true', help='Long Url will be shortened.')%0A    req_key = parser.add_argument_group(%22Required named arguments%22)%0A    req_key.add_argument('-k', '--key', type=str, help='Browser API key. Get it from Google Developer Console', required=True)%0A    req_key.add_argument('-u', '--url', type=str, help='URL which you want to shorten or expand.', required=True)%0A    args = parser.parse_args()%0A%0A    if args.expand and args.shorten:%0A        print('%5Cn--expand/--shorten are mutually exclusive%5Cn')%0A        parser.parse_args(%5B'--help'%5D)%0A    if not (args.shorten or args.expand):%0A        print('%5Cn--expand/--shorten is required%5Cn')%0A        parser.parse_args(%5B'--help'%5D)%0A    else:%0A        obj = GUrlShorten(args.key)%0A        if args.expand:%0A            print(obj.google_url_expand(args.url))%0A        elif args.shorten:%0A            print(obj.google_url_shorten(args.url))%0A        else:%0A            raise Exception('Magical Exception')%0A%0Aif __name__ == '__main__':%0A    sys.exit(main())%0A

Add google url shortener example