From feb16d9773df901032ad0c2f1d37e3da1b9bb814 Mon Sep 17 00:00:00 2001 From: Jose Manuel Delicado Date: Sat, 12 Aug 2017 12:54:18 +0200 Subject: [PATCH] Added compatibility with acorta.me URL shortener and set it as default --- src/url_shortener/__main__.py | 2 +- src/url_shortener/shorteners/__init__.py | 3 ++- src/url_shortener/shorteners/acortame.py | 26 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/url_shortener/shorteners/acortame.py diff --git a/src/url_shortener/__main__.py b/src/url_shortener/__main__.py index 56080ce7..216761d4 100644 --- a/src/url_shortener/__main__.py +++ b/src/url_shortener/__main__.py @@ -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__: diff --git a/src/url_shortener/shorteners/__init__.py b/src/url_shortener/shorteners/__init__.py index 53dce662..fc1bfc14 100644 --- a/src/url_shortener/shorteners/__init__.py +++ b/src/url_shortener/shorteners/__init__.py @@ -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"] diff --git a/src/url_shortener/shorteners/acortame.py b/src/url_shortener/shorteners/acortame.py new file mode 100644 index 00000000..77ae590c --- /dev/null +++ b/src/url_shortener/shorteners/acortame.py @@ -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