Exemple #1
0
def get_qr_code(url):
    shortener = Shortener('Google', api_key=API_KEY)
    shortener.short(url)
    try:
        return "Share your QR Code as \n {}".format(shortener.qrcode())
    except Exception as e:
        return "Ahh... Snap :O"
def test_qrcode():
    s = Shortener('TinyurlShortener')
    url = 'http://www.google.com'
    mock_url = '{}?url={}'.format(s.api_url, url)
    shorten = 'http://tinyurl.com/test'
    responses.add(responses.GET, mock_url, body=shorten,
                  match_querystring=True)
    s.short(url)
    # flake8: noqa
    assert s.qrcode() == 'http://chart.apis.google.com/chart?cht=qr&chl={0}&chs=120x120'.format(shorten)
def test_qrcode():
    s = Shortener('TinyurlShortener')
    url = 'http://www.google.com'
    mock_url = '{}?url={}'.format(s.api_url, url)
    shorten = 'http://tinyurl.com/test'
    responses.add(responses.GET, mock_url, body=shorten,
                  match_querystring=True)
    s.short(url)
    # flake8: noqa
    assert s.qrcode() == 'http://chart.apis.google.com/chart?cht=qr&chl={0}&chs=120x120'.format(shorten)
Exemple #4
0
 async def qrcode(self, ctx, url):
     """Creates a qrcode from a link."""
     shorten = Shortener('Bitly', bitly_token='dd800abec74d5b12906b754c630cdf1451aea9e0')
     short_link = shorten.short(url)
     async with aiohttp.get(shorten.qrcode(width=128, height=128)) as r:
         file = await r.content.read()
     number = random.randint(1000, 9999)
     fileloc = "data/useful/qrcode{}.png".format(number)
     with open(fileloc, 'wb') as f:
         f.write(file)
         file = None
         f = None
     await self.bot.send_file(ctx.message.channel, fp="data/useful/qrcode{}.png".format(number), filename="qrcode{}.png".format(number))
     os.remove("data/useful/qrcode{}.png".format(number))
def qr_generator(original_url, add):

    url = original_url + add
    shortener = Shortener('Tinyurl')
    shortener.short(url)
    link_image = shortener.qrcode(300, 300)
    #saving
    #filename = 'qrcode1'
    #filename = link_image.split('/')[-1]
    #r = requests.get(link_image, allow_redirects=True)
    #image = r.content
    #open(filename, 'wb').write(image)
    #shutil.copy(filename, os.path.join(BASE_DIR, 'media/images'))

    return link_image
class Shortlinks(Shortener):
    """
    Classe que lida com a compressão ou encurtamento do link.
    """
    def __init__(self):
        print('''
        Instruções: 
            Entre com uma URL válida e aperte enter.
            exemplo: https://dev.to/peteranglea/6-months-of-working-remotely-taught-me-a-thing-orten
        Opções:
            1. Encurtar a URL
            2. Decodificar uma URL encurtada
            3. Transformar URL em QR code
        ''')
        self.option = int(input("Escolha uma opção: "))
        self.url = str(input("Entre com a URL: "))
        self.shortener = Shortener('Tinyurl')
        if self.option == 1:
            self.short_url()
        elif self.option == 2:
            self.decode_url()
        elif self.option == 3:
            self.qrcode_url()
        else:
            print('Opção inválida.')

    def short_url(self):
        """
        Encurta uma URL
        """
        self.shortened_url = self.shortener.short(self.url)
        print("Short URL: " + self.shortened_url + "\n")

    def decode_url(self):
        """
        Descomprime uma URL
        """
        self.decoded_url = self.shortener.expand(self.url)
        print("URL decodificada: " + self.decoded_url + "\n")

    def qrcode_url(self):
        """
        Gera o QRCode da URL.
        """
        self.shortener.short(self.url)
        print(self.shortener.qrcode())
Exemple #7
0
def test_none_qrcode():
    shortener = Shortener(Shorteners.TINYURL)
    assert shortener.qrcode() is None
def test_none_qrcode():
    shortener = Shortener('TinyurlShortener')
    assert shortener.qrcode() is None
def test_none_qrcode():
    shortener = Shortener('TinyurlShortener')
    assert shortener.qrcode() is None
Exemple #10
0
with open('Sheet1.tsv', 'rb') as csvFile:
    reader = csv.reader(csvFile, delimiter='\t')
    for idx, row in enumerate(reader):

        try:
            assign = row[6]  #assignedTo
        except IndexError:
            assign = 'null'

        url = row[5]
        print(url)
        shortener = Shortener('Tinyurl', timeout=9000)
        shortURL = shortener.short(url)

        URL = shortener.qrcode().replace("120x120", "220x220")

        FILENAME = str(idx)
        FILENAME += ".png"

        urllib.urlretrieve(URL, filename=FILENAME)

        tableMiddle = u"<tr><td>"
        tableMiddle += row[0]  #Last Name
        tableMiddle += u"</td><td>"
        tableMiddle += row[1]  #First Name
        tableMiddle += u"</td><td>"
        tableMiddle += row[2]  #Address
        tableMiddle += u"</td><td>"
        tableMiddle += row[3]  #Phone
        tableMiddle += u"</td></tr>\n<tr><td>"
Exemple #11
0
print("4: Osdb.link\n")
print("5: Goog.gl\n")
print("6: TinyURL\n")
print("7: All of the Above\n")
print("8: Quit")


#Loops indefinitely until you pick a option
while ans != "1" and ans != "2" and ans != "3" and ans != "4" and ans != "5" and ans != "6" and ans != "7" and ans != "8": #Until a valid option is chosen..
	ans =  input("Which option would you like?: ")
	if ans == "1":
		bitly_url = bitly.short(link) #Shortens the link
		print(bitly_url) #Spits it out
		qrans = input("Would you like a QR Code for your link? (Y or N): ")
		if qrans == "Y":
			qr = bitly.qrcode() #Creates a qr code using google
			urllib.request.urlretrieve(qr, "bitly.png")
			print("[*] File saved as 'bitly.png' ")
		else:
			break
	elif ans == "2":
		isgd_url = isgd.short(link)
		print(isgd_url)
		qrans = input("Would you like a QR Code for your link? (Y or N): ")
		if qrans == "Y":
			qr = isgd.qrcode()
			urllib.request.urlretrieve(qr, "isgd.png")
			print("[*] File saved as 'isgd.png' ")
		else:
			break
	elif (ans == "3"):
def test_none_qrcode():
    shortener = Shortener(Shorteners.TINYURL)
    assert shortener.qrcode() is None
Exemple #13
0
with open('Sheet1.tsv', 'rb') as csvFile:
        reader = csv.reader(csvFile, delimiter='\t')
        for idx,row in enumerate(reader):
        
                try:
                    assign = row[6]  #assignedTo
                except IndexError:
                    assign = 'null'


		url = row[5]
		print(url)
		shortener = Shortener('Tinyurl', timeout=9000)
		shortURL = shortener.short(url)

		URL = shortener.qrcode().replace("120x120","220x220")
		
		FILENAME = str(idx)
		FILENAME += ".png"

		urllib.urlretrieve(URL, filename=FILENAME)
	
		
		tableMiddle = u"<tr><td>"
		tableMiddle += row[0] #Last Name
		tableMiddle += u"</td><td>"
		tableMiddle += row[1] #First Name
		tableMiddle += u"</td><td>"
		tableMiddle += row[2] #Address
		tableMiddle += u"</td><td>"
		tableMiddle += row[3] #Phone
def test_none_qrcode():
    shortener = Shortener(shorteners.TINYURL_SHORTENER)
    assert shortener.qrcode() is None