diff options
author | marc <a01200356@itesm.mx> | 2017-02-24 20:21:48 -0600 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2017-03-18 23:44:21 +0100 |
commit | 805fb02ed1fb7f8e006c8def7d76a0d1958364bf (patch) | |
tree | 530b3b98842965c2343ee5e9568853acc7fd064a /searx/engines/qwant.py | |
parent | e4d46d21c7ed2793edf446c4292971a853ed0e3d (diff) | |
download | searxng-805fb02ed1fb7f8e006c8def7d76a0d1958364bf.tar.gz searxng-805fb02ed1fb7f8e006c8def7d76a0d1958364bf.zip |
add language support for qwant
closes issue #863
Diffstat (limited to 'searx/engines/qwant.py')
-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 |