From 78939e7fb447eff2613200c448716870b9aa1c68 Mon Sep 17 00:00:00 2001 From: Ben Busby <33362396+benbusby@users.noreply.github.com> Date: Tue, 26 May 2020 10:47:40 -0600 Subject: [PATCH] Reworked google url routing --- app/filter.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/filter.py b/app/filter.py index 0478889..5ff46b7 100644 --- a/app/filter.py +++ b/app/filter.py @@ -12,7 +12,6 @@ LOGO_URL = GOOG_IMG + '_desk' BLANK_B64 = ''' data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAQAAAAnOwc2AAAAD0lEQVR42mNkwAIYh7IgAAVVAAuInjI5AAAAAElFTkSuQmCC ''' -GOOGLE_LINKS = ['/gmail', '/calendar', '/advanced_search'] def get_first_link(soup): @@ -175,10 +174,8 @@ class Filter: # Replace hrefs with only the intended destination (no "utm" type tags) for a in soup.find_all('a', href=True): href = a['href'].replace('https://www.google.com', '') - if href in GOOGLE_LINKS: - print(href) - if '/advanced_search' in href: - a.decompose() + if '/advanced_search' in href: + a.decompose() continue elif self.new_tab: a['target'] = '_blank' @@ -186,7 +183,9 @@ class Filter: result_link = urlparse.urlparse(href) 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()) new_search = '/search?q=' + enc_result.decode()