diff --git a/src/url_shortener/shorteners/acortame.py b/src/url_shortener/shorteners/acortame.py index 1f095683..4cd274d2 100644 --- a/src/url_shortener/shorteners/acortame.py +++ b/src/url_shortener/shorteners/acortame.py @@ -7,7 +7,6 @@ class AcortameShortener (URLShortener): super(AcortameShortener, self).__init__(*args, **kwargs) def _shorten (self, url): - answer = url api = requests.get ("https://acorta.me/api.php?action=shorturl&format=simple&url=" + urllib.quote(url)) if api.status_code == 200: diff --git a/src/url_shortener/shorteners/clckru.py b/src/url_shortener/shorteners/clckru.py index f72f9281..ba1d8bb2 100644 --- a/src/url_shortener/shorteners/clckru.py +++ b/src/url_shortener/shorteners/clckru.py @@ -1,19 +1,18 @@ import urllib - +import requests from url_shortener import URLShortener class ClckruShortener (URLShortener): def __init__ (self, *args, **kwargs): self.name = "clck.ru" - return super(ClckruShortener, self).__init__(*args, **kwargs) + super(ClckruShortener, self).__init__(*args, **kwargs) def _shorten (self, url): answer = url - api = urllib.urlopen ("http://clck.ru/--?url=" + urllib.quote(url)) - if api.getcode() == 200: - answer = api.read() - api.close() + api = requests.get ("http://clck.ru/--?url=" + urllib.quote(url)) + if api.status_code == 200: + answer = api.text return answer def created_url (self, url): diff --git a/src/url_shortener/shorteners/hkcim.py b/src/url_shortener/shorteners/hkcim.py index 3a47e16f..4c27ec82 100644 --- a/src/url_shortener/shorteners/hkcim.py +++ b/src/url_shortener/shorteners/hkcim.py @@ -1,5 +1,5 @@ import urllib - +import requests from url_shortener import URLShortener class HKCShortener (URLShortener): @@ -9,10 +9,9 @@ class HKCShortener (URLShortener): def _shorten (self, url): answer = url - api = urllib.urlopen ("http://hkc.im/yourls-api.php?action=shorturl&format=simple&url=" + urllib.quote(url)) - if api.getcode() == 200: - answer = api.read() - api.close() + api = requests.get ("http://hkc.im/yourls-api.php?action=shorturl&format=simple&url=" + urllib.quote(url)) + if api.status_code == 200: + answer = api.text return answer def created_url (self, url): diff --git a/src/url_shortener/shorteners/isgd.py b/src/url_shortener/shorteners/isgd.py index d2d25b33..ce46890f 100644 --- a/src/url_shortener/shorteners/isgd.py +++ b/src/url_shortener/shorteners/isgd.py @@ -1,19 +1,18 @@ import urllib - +import requests from url_shortener import URLShortener class IsgdShortener (URLShortener): def __init__ (self, *args, **kwargs): self.name = "Is.gd" - return super(IsgdShortener, self).__init__(*args, **kwargs) + super(IsgdShortener, self).__init__(*args, **kwargs) def _shorten (self, url): answer = url - api = urllib.urlopen ("http://is.gd/api.php?longurl=" + urllib.quote(url)) - if api.getcode() == 200: - answer = api.read() - api.close() + api = requests.get ("http://is.gd/api.php?longurl=" + urllib.quote(url)) + if api.status_code == 200: + answer = api.text return answer def created_url (self, url): diff --git a/src/url_shortener/shorteners/onjme.py b/src/url_shortener/shorteners/onjme.py index 0b0fd5a2..1a2ec992 100644 --- a/src/url_shortener/shorteners/onjme.py +++ b/src/url_shortener/shorteners/onjme.py @@ -1,5 +1,5 @@ import urllib - +import requests from url_shortener import URLShortener class OnjmeShortener (URLShortener): @@ -9,10 +9,9 @@ class OnjmeShortener (URLShortener): def _shorten (self, url): answer = url - api = urllib.urlopen ("http://onj.me/yourls-api.php?action=shorturl&format=simple&url=" + urllib.quote(url)) - if api.getcode() == 200: - answer = api.read() - api.close() + api = requests.get ("http://onj.me/yourls-api.php?action=shorturl&format=simple&url=" + urllib.quote(url)) + if api.status_code == 200: + answer = api.text return answer def created_url (self, url): diff --git a/src/url_shortener/shorteners/tinyarrows.py b/src/url_shortener/shorteners/tinyarrows.py index d9392fb7..cce2847c 100644 --- a/src/url_shortener/shorteners/tinyarrows.py +++ b/src/url_shortener/shorteners/tinyarrows.py @@ -1,5 +1,5 @@ import urllib - +import requests from url_shortener import URLShortener class TinyArrowsShortener (URLShortener): @@ -9,8 +9,10 @@ class TinyArrowsShortener (URLShortener): def _shorten (self, url): answer = url - answer = urllib.urlopen("http://tinyarro.ws/api-create.php?utfpure=1&url=%s" % urllib.quote(url)).read() + api = requests.get("http://tinyarro.ws/api-create.php?utfpure=1&url=%s" % urllib.quote(url)) + if api.status_code == 200: + answer = api.text return answer.decode('UTF-8') def created_url(self, url): - return False + return "tinyarro.ws" in url diff --git a/src/url_shortener/shorteners/tinyurl.py b/src/url_shortener/shorteners/tinyurl.py index 6f1b316e..79a7012e 100644 --- a/src/url_shortener/shorteners/tinyurl.py +++ b/src/url_shortener/shorteners/tinyurl.py @@ -1,4 +1,5 @@ from url_shortener import URLShortener +import requests import urllib class TinyurlShortener (URLShortener): def __init__(self, *args, **kwargs): @@ -6,12 +7,10 @@ class TinyurlShortener (URLShortener): super(TinyurlShortener, self).__init__(*args, **kwargs) def _shorten (self, url): - answer = url - api = urllib.urlopen ("http://tinyurl.com/api-create.php?url=" + urllib.quote(url)) - if api.getcode() == 200: - answer = api.read() - api.close() + api = requests.get ("http://tinyurl.com/api-create.php?url=" + urllib.quote(url)) + if api.status_code == 200: + answer = api.text return answer def created_url (self, url): diff --git a/src/url_shortener/shorteners/xedcc.py b/src/url_shortener/shorteners/xedcc.py index 8d466306..6741604e 100644 --- a/src/url_shortener/shorteners/xedcc.py +++ b/src/url_shortener/shorteners/xedcc.py @@ -1,5 +1,5 @@ import urllib - +import requests from url_shortener import URLShortener class XedccShortener (URLShortener): @@ -9,10 +9,9 @@ class XedccShortener (URLShortener): def _shorten (self, url): answer = url - api = urllib.urlopen ("http://xed.cc/yourls-api.php?action=shorturl&format=simple&url=" + urllib.quote(url)) - if api.getcode() == 200: - answer = api.read() - api.close() + api = requests.get ("http://xed.cc/yourls-api.php?action=shorturl&format=simple&url=" + urllib.quote(url)) + if api.status_code == 200: + answer = api.text return answer def created_url (self, url):