Reworked google url routing
parent
98d639883c
commit
78939e7fb4
|
@ -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,10 +174,8 @@ 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:
|
if '/advanced_search' in href:
|
||||||
print(href)
|
a.decompose()
|
||||||
if '/advanced_search' in href:
|
|
||||||
a.decompose()
|
|
||||||
continue
|
continue
|
||||||
elif self.new_tab:
|
elif self.new_tab:
|
||||||
a['target'] = '_blank'
|
a['target'] = '_blank'
|
||||||
|
@ -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()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue