From de0af09a33368a5f3fe6d4b1d64e5de8287866f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Novegil=20Cancelas?= Date: Wed, 29 Nov 2017 18:03:37 +0100 Subject: [PATCH] Added support for the i.gal shortener. This is a very basical implementation as i.gal requires an API key to work --- src/url_shortener/__main__.py | 2 +- src/url_shortener/shorteners/__init__.py | 3 ++- src/url_shortener/shorteners/igal.py | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/url_shortener/shorteners/igal.py diff --git a/src/url_shortener/__main__.py b/src/url_shortener/__main__.py index 216761d4..2d683b45 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.AcortameShortener + return shorteners.IgalShortener 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 fc1bfc14..8e0a3fd0 100644 --- a/src/url_shortener/shorteners/__init__.py +++ b/src/url_shortener/shorteners/__init__.py @@ -7,4 +7,5 @@ from tinyurl import TinyurlShortener from xedcc import XedccShortener from clckru import ClckruShortener from acortame import AcortameShortener -__all__ = ["HKCShortener", "IsgdShortener", "OnjmeShortener", "TinyArrowsShortener", "TinyurlShortener", "XedccShortener", "ClckruShortener", "AcortameShortener"] +from igal import IgalShortener +__all__ = ["HKCShortener", "IsgdShortener", "OnjmeShortener", "TinyArrowsShortener", "TinyurlShortener", "XedccShortener", "ClckruShortener", "AcortameShortener", "IgalShortener"] diff --git a/src/url_shortener/shorteners/igal.py b/src/url_shortener/shorteners/igal.py new file mode 100644 index 00000000..c68f4d79 --- /dev/null +++ b/src/url_shortener/shorteners/igal.py @@ -0,0 +1,18 @@ +from url_shortener import URLShortener +import requests +import urllib +class IgalShortener (URLShortener): + def __init__(self, *args, **kwargs): + self.name = "i.gal" + super(IgalShortener, self).__init__(*args, **kwargs) + + def _shorten (self, url): + answer = url + api = requests.get ("https://i.gal/api/v2/action/shorten?key=apikey&url=" + urllib.quote(url)) + if api.status_code == 200: + answer = api.text + return answer + + def created_url (self, url): + return 'i.gal' in url + \ No newline at end of file