mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
Now the URLS are expanded using requests. It means proxy support for URL shortener, and follow all redirections to get the final URL
This commit is contained in:
parent
f18a03d4a1
commit
ff05c9cb23
@ -1,6 +1,4 @@
|
|||||||
from httplib import HTTPConnection
|
import requests
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
|
|
||||||
class URLShortener (object):
|
class URLShortener (object):
|
||||||
|
|
||||||
@ -22,12 +20,8 @@ class URLShortener (object):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def unshorten(self, url):
|
def unshorten(self, url):
|
||||||
working = urlparse(url)
|
try:
|
||||||
if not working.netloc:
|
r=requests.get(url)
|
||||||
raise TypeError, "Unable to parse URL."
|
return r.url
|
||||||
con = HTTPConnection(working.netloc)
|
except:
|
||||||
con.connect()
|
return url #we cannot expand
|
||||||
con.request('GET', working.path)
|
|
||||||
resp = con.getresponse()
|
|
||||||
con.close()
|
|
||||||
return resp.getheader('location')
|
|
||||||
|
Loading…
Reference in New Issue
Block a user