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
|
||||
from urlparse import urlparse
|
||||
|
||||
import requests
|
||||
|
||||
class URLShortener (object):
|
||||
|
||||
@ -22,12 +20,8 @@ class URLShortener (object):
|
||||
raise NotImplementedError
|
||||
|
||||
def unshorten(self, url):
|
||||
working = urlparse(url)
|
||||
if not working.netloc:
|
||||
raise TypeError, "Unable to parse URL."
|
||||
con = HTTPConnection(working.netloc)
|
||||
con.connect()
|
||||
con.request('GET', working.path)
|
||||
resp = con.getresponse()
|
||||
con.close()
|
||||
return resp.getheader('location')
|
||||
try:
|
||||
r=requests.get(url)
|
||||
return r.url
|
||||
except:
|
||||
return url #we cannot expand
|
||||
|
Loading…
Reference in New Issue
Block a user