From 24756e73d3b88b59d83b6bbd3b4fd1a8f350123b Mon Sep 17 00:00:00 2001 From: Jose Manuel Delicado Date: Sat, 12 Aug 2017 21:03:52 +0200 Subject: [PATCH] acortame.py: use requests instead of urllib, so we can shorten and unshorten URLS through proxy servers --- src/url_shortener/shorteners/acortame.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/url_shortener/shorteners/acortame.py b/src/url_shortener/shorteners/acortame.py index 77ae590c..08ef53f6 100644 --- a/src/url_shortener/shorteners/acortame.py +++ b/src/url_shortener/shorteners/acortame.py @@ -1,4 +1,5 @@ from url_shortener import URLShortener +import requests import urllib class AcortameShortener (URLShortener): def __init__(self, *args, **kwargs): @@ -8,10 +9,9 @@ class AcortameShortener (URLShortener): 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() + api = requests.get ("https://acorta.me/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): @@ -20,7 +20,7 @@ class AcortameShortener (URLShortener): 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() + api = requests.get ("https://acorta.me/api.php?action=expand&format=simple&shorturl=" + urllib.quote(url)) + if api.status_code == 200: + answer = api.text return answer