Reworked google url routing

main
Ben Busby 2020-05-26 10:47:40 -06:00
parent 98d639883c
commit 78939e7fb4
1 changed files with 5 additions and 6 deletions

View File

@ -12,7 +12,6 @@ LOGO_URL = GOOG_IMG + '_desk'
BLANK_B64 = ''' BLANK_B64 = '''
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAQAAAAnOwc2AAAAD0lEQVR42mNkwAIYh7IgAAVVAAuInjI5AAAAAElFTkSuQmCC data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAQAAAAnOwc2AAAAD0lEQVR42mNkwAIYh7IgAAVVAAuInjI5AAAAAElFTkSuQmCC
''' '''
GOOGLE_LINKS = ['/gmail', '/calendar', '/advanced_search']
def get_first_link(soup): def get_first_link(soup):
@ -175,8 +174,6 @@ class Filter:
# Replace hrefs with only the intended destination (no "utm" type tags) # Replace hrefs with only the intended destination (no "utm" type tags)
for a in soup.find_all('a', href=True): for a in soup.find_all('a', href=True):
href = a['href'].replace('https://www.google.com', '') href = a['href'].replace('https://www.google.com', '')
if href in GOOGLE_LINKS:
print(href)
if '/advanced_search' in href: if '/advanced_search' in href:
a.decompose() a.decompose()
continue continue
@ -186,7 +183,9 @@ class Filter:
result_link = urlparse.urlparse(href) result_link = urlparse.urlparse(href)
query_link = parse_qs(result_link.query)['q'][0] if '?q=' in href else '' query_link = parse_qs(result_link.query)['q'][0] if '?q=' in href else ''
if '/search?q=' in href: if query_link.startswith('/'):
a['href'] = 'https://google.com' + query_link
elif '/search?q=' in href:
enc_result = Fernet(self.secret_key).encrypt(query_link.encode()) enc_result = Fernet(self.secret_key).encrypt(query_link.encode())
new_search = '/search?q=' + enc_result.decode() new_search = '/search?q=' + enc_result.decode()