Added compatibility with acorta.me URL shortener and set it as default

This commit is contained in:
Jose Manuel Delicado 2017-08-12 12:54:18 +02:00
parent 5b47e8806a
commit feb16d9773
3 changed files with 29 additions and 2 deletions

View File

@ -25,7 +25,7 @@ def unshorten (url, service=None, **kwargs):
def default_service ():
return shorteners.TinyurlShortener
return shorteners.AcortameShortener
def find_service (service, **kwargs):
for i in shorteners.__all__:

View File

@ -6,4 +6,5 @@ from tinyarrows import TinyArrowsShortener
from tinyurl import TinyurlShortener
from xedcc import XedccShortener
from clckru import ClckruShortener
__all__ = ["HKCShortener", "IsgdShortener", "OnjmeShortener", "TinyArrowsShortener", "TinyurlShortener", "XedccShortener", "ClckruShortener"]
from acortame import AcortameShortener
__all__ = ["HKCShortener", "IsgdShortener", "OnjmeShortener", "TinyArrowsShortener", "TinyurlShortener", "XedccShortener", "ClckruShortener", "AcortameShortener"]

View File

@ -0,0 +1,26 @@
from url_shortener import URLShortener
import urllib
class AcortameShortener (URLShortener):
def __init__(self, *args, **kwargs):
self.name = "acorta.me"
super(AcortameShortener, self).__init__(*args, **kwargs)
def _shorten (self, url):
answer = url
api = urllib.urlopen ("https://acorta.me/api.php?action=shorturl&format=simple&url=" + urllib.quote(url))
if api.getcode() == 200:
answer = api.read()
api.close()
return answer
def created_url (self, url):
return 'acorta.me' in url
def unshorten (self, url):
answer = url
api = urllib.urlopen ("https://acorta.me/api.php?action=expand&format=simple&shorturl=" + urllib.quote(url))
answer = api.read()
api.close()
return answer