diff options
author | a01200356 <a01200356@itesm.mx> | 2016-06-03 00:14:23 -0500 |
---|---|---|
committer | marc <a01200356@itesm.mx> | 2016-07-12 23:44:39 -0500 |
commit | 8fc4b8156affc9e7f00db0988ccd627b3eaae8a7 (patch) | |
tree | d85901fdd96e2968f7a21800fde891c0dcd181b3 /searx/engines/duckduckgo.py | |
parent | 3fd405dcd3fd46d5b6f2fe1df625eedf0f1fbe02 (diff) | |
download | searxng-8fc4b8156affc9e7f00db0988ccd627b3eaae8a7.tar.gz searxng-8fc4b8156affc9e7f00db0988ccd627b3eaae8a7.zip |
[fix] multilingual duckduckgo
only works if both country and language are set
Diffstat (limited to 'searx/engines/duckduckgo.py')
-rw-r--r-- | searx/engines/duckduckgo.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/searx/engines/duckduckgo.py b/searx/engines/duckduckgo.py index 373ce1b2d..714c27228 100644 --- a/searx/engines/duckduckgo.py +++ b/searx/engines/duckduckgo.py @@ -11,8 +11,6 @@ @parse url, title, content @todo rewrite to api - @todo language support - (the current used site does not support language-change) """ from urllib import urlencode @@ -39,13 +37,22 @@ def request(query, params): offset = (params['pageno'] - 1) * 30 if params['language'] == 'all': - locale = 'en-us' + locale = None else: - locale = params['language'].replace('_', '-').lower() - - params['url'] = url.format( - query=urlencode({'q': query, 'kl': locale}), - offset=offset) + locale = params['language'].split('_') + if len(locale) == 2: + # country code goes first + locale = locale[1].lower() + '-' + locale[0].lower() + else: + # doesn't actually do anything because ddg requires both country and language + locale = locale[0].lower() + + if locale: + params['url'] = url.format( + query=urlencode({'q': query, 'kl': locale}), offset=offset) + else: + params['url'] = url.format( + query=urlencode({'q': query}), offset=offset) return params |