Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active Jul 16, 2017
Embed
What would you like to do?
Acortar links usando Python y las apis de Coinurl, ShinkIn, Ouo y Linkbucks
import urllib.request, json
from urllib.parse import quote
from urllib.request import Request, urlopen
class Acortar:
def __init__(self, link):
self.link = link
self.link_seguro = quote( link.encode('UTF-8') )
def responder_texto_plano(self, cadena):
return cadena.decode('UTF-8')
def con_coinurl(self):
uuid = "tu_uuid_aquí"
link_peticion = "https://coinurl.com/api.php?uuid={:s}&url={:s}".format(uuid, self.link_seguro)
peticion = urllib.request.Request(link_peticion , headers = {'User-Agent': 'Otro navegador'})
resultado = urllib.request.urlopen(peticion).read()
return self.responder_texto_plano(resultado)
def con_shinkin(self):
api_key = "tu_api_key_aquí"
link_peticion = "https://shink.in/stxt/0/id/107990/auth_token/{:s}?s={:s}".format(api_key, self.link_seguro)
peticion = urllib.request.Request(link_peticion , headers = {'User-Agent': 'Otro navegador'})
resultado = urllib.request.urlopen(peticion).read()
return self.responder_texto_plano(resultado)
def con_ouo(self):
api_key = "tu_api_key_aquí"
link_peticion = "http://ouo.io/api/{:s}?s={:s}".format(api_key, self.link_seguro)
peticion = urllib.request.Request(link_peticion , headers = {'User-Agent': 'Otro navegador'})
resultado = urllib.request.urlopen(peticion).read()
return self.responder_texto_plano(resultado)
def con_linkbucks(self):
api_password = "tu_api_password_aquí"
usuario = "tu_usuario_aquí"
url = 'https://www.linkbucks.com/api/createLink/single'
datos = '{{"user" : "{:s}", "apiPassword" : "{:s}", "originalLink" : "{:s}", "adType" : 2, "contentType" : 1, "domain" : "linkbucks.com"}}'.format(usuario, api_password, self.link).encode()
request = Request(url, datos , headers = {'User-Agent': 'Otro navegador'})
respuesta = urlopen(request).read().decode()
decodificado = json.loads(respuesta)
return decodificado["link"]
def imprimir_menu():
while True:
while True:
link = input("Escribe el enlace que deseas acortar: ")
if link is not "":
break
opcion = int(input("""
[ 1 ] - Coinurl
[ 2 ] - Shink in
[ 3 ] - Ouo
[ 4 ] - Linkbucks
[ -1 ] - Salir
Elige:"""))
if opcion is 1:
print(Acortar(link).con_coinurl())
elif opcion is 2:
print(Acortar(link).con_shinkin())
elif opcion is 3:
print(Acortar(link).con_ouo())
elif opcion is 4:
print(Acortar(link).con_linkbucks())
else:
break
imprimir_menu()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment