summaryrefslogtreecommitdiff
path: root/searx/engines/bing_images.py
diff options
context:
space:
mode:
authorMarc Abonce Seguin <marc-abonce@mailbox.org>2018-02-28 22:30:48 -0600
committerMarc Abonce Seguin <marc-abonce@mailbox.org>2018-03-27 00:08:03 -0600
commit772c048d01c7585fd60afca1ce30a1914e6e5b4a (patch)
tree96a5662897df2bcf0ab53456e0a67ace998f2169 /searx/engines/bing_images.py
parentd1eae9359f8c5920632a730744ea2208070f06da (diff)
downloadsearxng-772c048d01c7585fd60afca1ce30a1914e6e5b4a.tar.gz
searxng-772c048d01c7585fd60afca1ce30a1914e6e5b4a.zip
refactor engine's search language handling
Add match_language function in utils to match any user given language code with a list of engine's supported languages. Also add language_aliases dict on each engine to translate standard language codes into the custom codes used by the engine.
Diffstat (limited to 'searx/engines/bing_images.py')
-rw-r--r--searx/engines/bing_images.py23
1 files changed, 2 insertions, 21 deletions
diff --git a/searx/engines/bing_images.py b/searx/engines/bing_images.py
index 15679056c..66e14c01f 100644
--- a/searx/engines/bing_images.py
+++ b/searx/engines/bing_images.py
@@ -19,6 +19,7 @@ from lxml import html
from json import loads
import re
from searx.url_utils import urlencode
+from searx.utils import match_language
# engine dependent config
categories = ['images']
@@ -46,26 +47,6 @@ safesearch_types = {2: 'STRICT',
_quote_keys_regex = re.compile('({|,)([a-z][a-z0-9]*):(")', re.I | re.U)
-# get supported region code
-def get_region_code(lang, lang_list=None):
- region = None
- if lang in (lang_list or supported_languages):
- region = lang
- elif lang.startswith('no'):
- region = 'nb-NO'
- else:
- # try to get a supported country code with language
- lang = lang.split('-')[0]
- for lc in (lang_list or supported_languages):
- if lang == lc.split('-')[0]:
- region = lc
- break
- if region:
- return region.lower()
- else:
- return 'en-us'
-
-
# do search-request
def request(query, params):
offset = (params['pageno'] - 1) * 10 + 1
@@ -74,7 +55,7 @@ def request(query, params):
query=urlencode({'q': query}),
offset=offset)
- language = get_region_code(params['language'])
+ language = match_language(params['language'], supported_languages).lower()
params['cookies']['SRCHHPGUSR'] = \
'ADLT=' + safesearch_types.get(params['safesearch'], 'DEMOTE')