summaryrefslogtreecommitdiff
path: root/searx/engines/bing_images.py
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-12-27 19:11:01 +0100
committerGitHub <noreply@github.com>2021-12-27 19:11:01 +0100
commitc6922ae7c5e53f695d5f5f8704b10b4e2815cda4 (patch)
tree9c0456ad1a1d9d375311ccd8c9bd3eafd0779114 /searx/engines/bing_images.py
parent54bce130f9074c3d63009237b014c727a1443cc5 (diff)
parentd84226bf63757b1d4245ab26e9c081daf42389aa (diff)
Merge pull request #619 from dalf/apply-black
Apply black
Diffstat (limited to 'searx/engines/bing_images.py')
-rw-r--r--searx/engines/bing_images.py59
1 files changed, 30 insertions, 29 deletions
diff --git a/searx/engines/bing_images.py b/searx/engines/bing_images.py
index 4bee9bc7d..73b61b896 100644
--- a/searx/engines/bing_images.py
+++ b/searx/engines/bing_images.py
@@ -6,10 +6,13 @@
from urllib.parse import urlencode
from lxml import html
from json import loads
-from searx.utils import match_language
+from searx.utils import match_language
from searx.engines.bing import language_aliases
-from searx.engines.bing import _fetch_supported_languages, supported_languages_url # NOQA # pylint: disable=unused-import
+from searx.engines.bing import ( # pylint: disable=unused-import
+ _fetch_supported_languages,
+ supported_languages_url,
+)
# about
about = {
@@ -31,39 +34,33 @@ number_of_results = 28
# search-url
base_url = 'https://www.bing.com/'
-search_string = 'images/search'\
- '?{query}'\
- '&count={count}'\
- '&first={first}'\
+search_string = (
+ # fmt: off
+ 'images/search'
+ '?{query}'
+ '&count={count}'
+ '&first={first}'
'&tsc=ImageHoverTitle'
+ # fmt: on
+)
time_range_string = '&qft=+filterui:age-lt{interval}'
-time_range_dict = {'day': '1440',
- 'week': '10080',
- 'month': '43200',
- 'year': '525600'}
+time_range_dict = {'day': '1440', 'week': '10080', 'month': '43200', 'year': '525600'}
# safesearch definitions
-safesearch_types = {2: 'STRICT',
- 1: 'DEMOTE',
- 0: 'OFF'}
+safesearch_types = {2: 'STRICT', 1: 'DEMOTE', 0: 'OFF'}
# do search-request
def request(query, params):
offset = ((params['pageno'] - 1) * number_of_results) + 1
- search_path = search_string.format(
- query=urlencode({'q': query}),
- count=number_of_results,
- first=offset)
+ search_path = search_string.format(query=urlencode({'q': query}), count=number_of_results, first=offset)
language = match_language(params['language'], supported_languages, language_aliases).lower()
- params['cookies']['SRCHHPGUSR'] = \
- 'ADLT=' + safesearch_types.get(params['safesearch'], 'DEMOTE')
+ params['cookies']['SRCHHPGUSR'] = 'ADLT=' + safesearch_types.get(params['safesearch'], 'DEMOTE')
- params['cookies']['_EDGE_S'] = 'mkt=' + language +\
- '&ui=' + language + '&F=1'
+ params['cookies']['_EDGE_S'] = 'mkt=' + language + '&ui=' + language + '&F=1'
params['url'] = base_url + search_path
if params['time_range'] in time_range_dict:
@@ -92,14 +89,18 @@ def response(resp):
# strip 'Unicode private use area' highlighting, they render to Tux
# the Linux penguin and a standing diamond on my machine...
title = m.get('t', '').replace('\ue000', '').replace('\ue001', '')
- results.append({'template': 'images.html',
- 'url': m['purl'],
- 'thumbnail_src': m['turl'],
- 'img_src': m['murl'],
- 'content': '',
- 'title': title,
- 'source': source,
- 'img_format': img_format})
+ results.append(
+ {
+ 'template': 'images.html',
+ 'url': m['purl'],
+ 'thumbnail_src': m['turl'],
+ 'img_src': m['murl'],
+ 'content': '',
+ 'title': title,
+ 'source': source,
+ 'img_format': img_format,
+ }
+ )
except:
continue