From 8c92b381a2380d3ea12289724638b22d431f9b89 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Thu, 23 Dec 2021 17:01:49 -0700 Subject: [PATCH] Remove default country param The country URL param ('gl') is no longer set to 'US' by default, and is omitted from the search entirely unless explicitly set by the user. This change was made in an attempt to cut back on the number of captchas experienced by certain users self-hosting who experienced a decreased amount of captchas when this configuration setting was removed. Fixes #558 --- app/models/config.py | 2 +- app/request.py | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/models/config.py b/app/models/config.py index 5595002..2bb96ea 100644 --- a/app/models/config.py +++ b/app/models/config.py @@ -17,7 +17,7 @@ class Config: self.block = os.getenv('WHOOGLE_CONFIG_BLOCK', '') self.block_title = os.getenv('WHOOGLE_CONFIG_BLOCK_TITLE', '') self.block_url = os.getenv('WHOOGLE_CONFIG_BLOCK_URL', '') - self.country = os.getenv('WHOOGLE_CONFIG_COUNTRY', 'US') + self.country = os.getenv('WHOOGLE_CONFIG_COUNTRY', '') self.theme = os.getenv('WHOOGLE_CONFIG_THEME', 'system') self.safe = read_config_bool('WHOOGLE_CONFIG_SAFE') self.dark = read_config_bool('WHOOGLE_CONFIG_DARK') # deprecated diff --git a/app/request.py b/app/request.py index 9850a1b..d7157af 100644 --- a/app/request.py +++ b/app/request.py @@ -107,9 +107,9 @@ def gen_query(query, args, config) -> str: [_ for _ in lang if not _.isdigit()] )) if lang else '' else: - param_dict['lr'] = '&lr=' + ( - config.lang_search if config.lang_search else '' - ) + param_dict['lr'] = ( + '&lr=' + config.lang_search + ) if config.lang_search else '' # 'nfpr' defines the exclusion of results from an auto-corrected query if 'nfpr' in args: @@ -120,11 +120,12 @@ def gen_query(query, args, config) -> str: if 'chips' in args: param_dict['chips'] = '&chips=' + args.get('chips') - param_dict['gl'] = ('&gl=' + config.country) if config.country else '' - param_dict['hl'] = '&hl=' + ( - config.lang_interface.replace('lang_', '') - if config.lang_interface else '' - ) + param_dict['gl'] = ( + '&gl=' + config.country + ) if config.country else '' + param_dict['hl'] = ( + '&hl=' + config.lang_interface.replace('lang_', '') + ) if config.lang_interface else '' param_dict['safe'] = '&safe=' + ('active' if config.safe else 'off') # Block all sites specified in the user config @@ -218,7 +219,10 @@ class Request: list: The list of matches for possible search suggestions """ - ac_query = dict(hl=self.language, q=query) + ac_query = dict(q=query) + if self.language: + ac_query['hl'] = self.language + response = self.send(base_url=AUTOCOMPLETE_URL, query=urlparse.urlencode(ac_query)).text