mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 19:28:09 -06:00
Added compatibility with acorta.me URL shortener and set it as default
This commit is contained in:
parent
5b47e8806a
commit
feb16d9773
@ -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__:
|
||||
|
@ -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"]
|
||||
|
26
src/url_shortener/shorteners/acortame.py
Normal file
26
src/url_shortener/shorteners/acortame.py
Normal 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
|
Loading…
Reference in New Issue
Block a user