Fix pep8 issues, move hostname declaration out of loop
This commit is contained in:
parent
e2ada2684b
commit
b5370aef70
|
@ -27,7 +27,7 @@ SITE_ALTS = {
|
||||||
'youtube.com': os.getenv('WHOOGLE_ALT_YT', 'invidious.snopyta.org'),
|
'youtube.com': os.getenv('WHOOGLE_ALT_YT', 'invidious.snopyta.org'),
|
||||||
'instagram.com': os.getenv('WHOOGLE_ALT_IG', 'bibliogram.art/u'),
|
'instagram.com': os.getenv('WHOOGLE_ALT_IG', 'bibliogram.art/u'),
|
||||||
'reddit.com': os.getenv('WHOOGLE_ALT_RD', 'libredd.it'),
|
'reddit.com': os.getenv('WHOOGLE_ALT_RD', 'libredd.it'),
|
||||||
'medium.com': os.getenv('WHOOGLE_ALT_MD','scribe.rip'),
|
'medium.com': os.getenv('WHOOGLE_ALT_MD', 'scribe.rip'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,16 +73,14 @@ def get_site_alt(link: str) -> str:
|
||||||
str: An updated (or ignored) result link
|
str: An updated (or ignored) result link
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
# Need to replace full hostname with alternative to encapsulate
|
||||||
|
# subdomains as well
|
||||||
|
hostname = urlparse.urlparse(link).hostname
|
||||||
|
|
||||||
for site_key in SITE_ALTS.keys():
|
for site_key in SITE_ALTS.keys():
|
||||||
if site_key not in link:
|
if not hostname or site_key not in hostname:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Need to replace full hostname with alternative to encapsulate
|
|
||||||
# subdomains as well
|
|
||||||
|
|
||||||
hostname = urlparse.urlparse(link).hostname
|
|
||||||
|
|
||||||
link = link.replace(hostname, SITE_ALTS[site_key])
|
link = link.replace(hostname, SITE_ALTS[site_key])
|
||||||
for prefix in SKIP_PREFIX:
|
for prefix in SKIP_PREFIX:
|
||||||
link = link.replace(prefix, '//')
|
link = link.replace(prefix, '//')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user