diff options
Diffstat (limited to 'searx/engines')
-rw-r--r-- | searx/engines/qwant.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/searx/engines/qwant.py b/searx/engines/qwant.py index 67803fa94..56282fdba 100644 --- a/searx/engines/qwant.py +++ b/searx/engines/qwant.py @@ -20,6 +20,7 @@ from searx.utils import html_to_text categories = None paging = True language_support = True +supported_languages_url = 'https://qwant.com/region' category_to_keyword = {'general': 'web', 'images': 'images', @@ -46,6 +47,13 @@ def request(query, params): # add language tag if specified if params['language'] != 'all': + if params['language'].find('-') < 0: + # tries to get a country code from language + for lang in supported_languages: + lc = lang.split('-') + if params['language'] == lc[0]: + params['language'] = lang + break params['url'] += '&locale=' + params['language'].replace('-', '_').lower() return params @@ -96,5 +104,21 @@ def response(resp): 'publishedDate': published_date, 'content': content}) - # return results return results + + +# get supported languages from their site +def _fetch_supported_languages(resp): + # list of regions is embedded in page as a js object + response_text = resp.text + response_text = response_text[response_text.find('regionalisation'):] + response_text = response_text[response_text.find('{'):response_text.find(');')] + + regions_json = loads(response_text) + + supported_languages = [] + for lang in regions_json['languages'].values(): + for country in lang['countries']: + supported_languages.append(lang['code'] + '-' + country) + + return supported_languages |