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
main
Ben Busby 2021-12-23 17:01:49 -07:00
parent 95be59eaab
commit 8c92b381a2
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1
2 changed files with 14 additions and 10 deletions

View File

@ -17,7 +17,7 @@ class Config:
self.block = os.getenv('WHOOGLE_CONFIG_BLOCK', '') self.block = os.getenv('WHOOGLE_CONFIG_BLOCK', '')
self.block_title = os.getenv('WHOOGLE_CONFIG_BLOCK_TITLE', '') self.block_title = os.getenv('WHOOGLE_CONFIG_BLOCK_TITLE', '')
self.block_url = os.getenv('WHOOGLE_CONFIG_BLOCK_URL', '') 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.theme = os.getenv('WHOOGLE_CONFIG_THEME', 'system')
self.safe = read_config_bool('WHOOGLE_CONFIG_SAFE') self.safe = read_config_bool('WHOOGLE_CONFIG_SAFE')
self.dark = read_config_bool('WHOOGLE_CONFIG_DARK') # deprecated self.dark = read_config_bool('WHOOGLE_CONFIG_DARK') # deprecated

View File

@ -107,9 +107,9 @@ def gen_query(query, args, config) -> str:
[_ for _ in lang if not _.isdigit()] [_ for _ in lang if not _.isdigit()]
)) if lang else '' )) if lang else ''
else: else:
param_dict['lr'] = '&lr=' + ( param_dict['lr'] = (
config.lang_search if config.lang_search else '' '&lr=' + config.lang_search
) ) if config.lang_search else ''
# 'nfpr' defines the exclusion of results from an auto-corrected query # 'nfpr' defines the exclusion of results from an auto-corrected query
if 'nfpr' in args: if 'nfpr' in args:
@ -120,11 +120,12 @@ def gen_query(query, args, config) -> str:
if 'chips' in args: if 'chips' in args:
param_dict['chips'] = '&chips=' + args.get('chips') param_dict['chips'] = '&chips=' + args.get('chips')
param_dict['gl'] = ('&gl=' + config.country) if config.country else '' param_dict['gl'] = (
param_dict['hl'] = '&hl=' + ( '&gl=' + config.country
config.lang_interface.replace('lang_', '') ) if config.country else ''
if config.lang_interface 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') param_dict['safe'] = '&safe=' + ('active' if config.safe else 'off')
# Block all sites specified in the user config # Block all sites specified in the user config
@ -218,7 +219,10 @@ class Request:
list: The list of matches for possible search suggestions 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, response = self.send(base_url=AUTOCOMPLETE_URL,
query=urlparse.urlencode(ac_query)).text query=urlparse.urlencode(ac_query)).text