Exemple #1
0
    def test_shorten_url_without_key(self):
        service = Googl()
        generated_short_url = service.shorten_url(self.test_long_url)

        self.assertEqual(self.test_short_url, generated_short_url)
            sys.exit(-1)

        try:
            service.write_qr_image(options.short_url, options.qr_img_path)
        except ShortenerServiceError, e:
            print e

        if os.path.exists(options.qr_img_path):
            print 'Wrote the QR code for %s to %s' %(options.short_url, options.qr_img_path)
        sys.exit(0)

    # Shorten a URL.
    if options.long_url:
        try:
            if 'bit.ly' == options.service and options.domain:
                short_url = service.shorten_url(options.long_url, domain=options.domain)
            else:
                short_url = service.shorten_url(options.long_url)
            print short_url
        except ShortenerServiceError, e:
            print e
        sys.exit(0)

    # Expand a short url.
    if options.short_url:
        try:
            long_url = service.expand_url(options.short_url)
            print long_url
        except ShortenerServiceError, e:
            print e
        sys.exit(0)
Exemple #3
0
	def shorten_link(self, link):
		shortener = Googl()
		return shortener.shorten_url(link)
Exemple #4
0
    def test_shorten_url_without_key(self):
        service = Googl()
        generated_short_url = service.shorten_url(self.test_long_url)

        self.assertEqual(self.test_short_url, generated_short_url)
        try:
            service.write_qr_image(options.short_url, options.qr_img_path)
        except ShortenerServiceError, e:
            print e

        if os.path.exists(options.qr_img_path):
            print 'Wrote the QR code for %s to %s' % (options.short_url,
                                                      options.qr_img_path)
        sys.exit(0)

    # Shorten a URL.
    if options.long_url:
        try:
            if 'bit.ly' == options.service and options.domain:
                short_url = service.shorten_url(options.long_url,
                                                domain=options.domain)
            else:
                short_url = service.shorten_url(options.long_url)
            print short_url
        except ShortenerServiceError, e:
            print e
        sys.exit(0)

    # Expand a short url.
    if options.short_url:
        try:
            long_url = service.expand_url(options.short_url)
            print long_url
        except ShortenerServiceError, e:
            print e
        sys.exit(0)