mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-23 03:38:08 -06:00
acortame.py: use requests instead of urllib, so we can shorten and unshorten URLS through proxy servers
This commit is contained in:
parent
feb16d9773
commit
24756e73d3
@ -1,4 +1,5 @@
|
|||||||
from url_shortener import URLShortener
|
from url_shortener import URLShortener
|
||||||
|
import requests
|
||||||
import urllib
|
import urllib
|
||||||
class AcortameShortener (URLShortener):
|
class AcortameShortener (URLShortener):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@ -8,10 +9,9 @@ class AcortameShortener (URLShortener):
|
|||||||
def _shorten (self, url):
|
def _shorten (self, url):
|
||||||
|
|
||||||
answer = url
|
answer = url
|
||||||
api = urllib.urlopen ("https://acorta.me/api.php?action=shorturl&format=simple&url=" + urllib.quote(url))
|
api = requests.get ("https://acorta.me/api.php?action=shorturl&format=simple&url=" + urllib.quote(url))
|
||||||
if api.getcode() == 200:
|
if api.status_code == 200:
|
||||||
answer = api.read()
|
answer = api.text
|
||||||
api.close()
|
|
||||||
return answer
|
return answer
|
||||||
|
|
||||||
def created_url (self, url):
|
def created_url (self, url):
|
||||||
@ -20,7 +20,7 @@ class AcortameShortener (URLShortener):
|
|||||||
def unshorten (self, url):
|
def unshorten (self, url):
|
||||||
|
|
||||||
answer = url
|
answer = url
|
||||||
api = urllib.urlopen ("https://acorta.me/api.php?action=expand&format=simple&shorturl=" + urllib.quote(url))
|
api = requests.get ("https://acorta.me/api.php?action=expand&format=simple&shorturl=" + urllib.quote(url))
|
||||||
answer = api.read()
|
if api.status_code == 200:
|
||||||
api.close()
|
answer = api.text
|
||||||
return answer
|
return answer
|
||||||
|
Loading…
Reference in New Issue
Block a user