mirror of
https://github.com/cquest/tootbot.git
synced 2024-11-23 20:11:06 +00:00
handle local path redirects
This commit is contained in:
parent
e3292c74bd
commit
1165374824
|
@ -18,7 +18,11 @@ import requests
|
||||||
def unredir(redir):
|
def unredir(redir):
|
||||||
r = requests.get(redir, allow_redirects=False)
|
r = requests.get(redir, allow_redirects=False)
|
||||||
while r.status_code in {301, 302}:
|
while r.status_code in {301, 302}:
|
||||||
redir = r.headers.get('Location')
|
if 'http' not in r.headers.get('Location'):
|
||||||
|
redir = re.sub(r'(https?://.*)/.*', r'\1', redir) + \
|
||||||
|
r.headers.get('Location')
|
||||||
|
else:
|
||||||
|
redir = r.headers.get('Location')
|
||||||
print('redir', redir)
|
print('redir', redir)
|
||||||
if '//ow.ly/' in redir or '//bit.ly/' in redir:
|
if '//ow.ly/' in redir or '//bit.ly/' in redir:
|
||||||
redir = redir.replace('https://ow.ly/', 'http://ow.ly/') # only http
|
redir = redir.replace('https://ow.ly/', 'http://ow.ly/') # only http
|
||||||
|
|
Loading…
Reference in New Issue
Block a user