diff options
author | marc <a01200356@itesm.mx> | 2016-07-14 16:36:52 -0500 |
---|---|---|
committer | marc <a01200356@itesm.mx> | 2016-07-14 16:36:52 -0500 |
commit | aac4ed6971c875077014d13ab85a1259a14b223b (patch) | |
tree | bd7dd126f94c1bd0b0c55a2c626eb22b54c9f025 /searx/engines/duckduckgo.py | |
parent | 8fc4b8156affc9e7f00db0988ccd627b3eaae8a7 (diff) | |
download | searxng-aac4ed6971c875077014d13ab85a1259a14b223b.tar.gz searxng-aac4ed6971c875077014d13ab85a1259a14b223b.zip |
[fix] guess country code if not specified in duckduckgo engine
Diffstat (limited to 'searx/engines/duckduckgo.py')
-rw-r--r-- | searx/engines/duckduckgo.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/searx/engines/duckduckgo.py b/searx/engines/duckduckgo.py index 714c27228..d29e4416a 100644 --- a/searx/engines/duckduckgo.py +++ b/searx/engines/duckduckgo.py @@ -16,6 +16,7 @@ from urllib import urlencode from lxml.html import fromstring from searx.engines.xpath import extract_text +from searx.languages import language_codes # engine dependent config categories = ['general'] @@ -44,8 +45,14 @@ def request(query, params): # country code goes first locale = locale[1].lower() + '-' + locale[0].lower() else: - # doesn't actually do anything because ddg requires both country and language + # tries to get a country code from language locale = locale[0].lower() + lang_codes = [x[0] for x in language_codes] + for lc in lang_codes: + lc = lc.split('_') + if locale == lc[0]: + locale = lc[1].lower() + '-' + lc[0].lower() + break if locale: params['url'] = url.format( |