Fix pep8 issues, move hostname declaration out of loop

This commit is contained in:
Ben Busby 2021-10-16 12:11:39 -06:00
parent e2ada2684b
commit b5370aef70
No known key found for this signature in database
GPG Key ID: 339B7B7EB5333D14

View File

@ -27,7 +27,7 @@ SITE_ALTS = {
'youtube.com': os.getenv('WHOOGLE_ALT_YT', 'invidious.snopyta.org'),
'instagram.com': os.getenv('WHOOGLE_ALT_IG', 'bibliogram.art/u'),
'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
"""
for site_key in SITE_ALTS.keys():
if site_key not in link:
continue
# Need to replace full hostname with alternative to encapsulate
# subdomains as well
hostname = urlparse.urlparse(link).hostname
for site_key in SITE_ALTS.keys():
if not hostname or site_key not in hostname:
continue
link = link.replace(hostname, SITE_ALTS[site_key])
for prefix in SKIP_PREFIX:
link = link.replace(prefix, '//')