diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2023-09-27 18:24:33 +0200 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2023-10-01 08:01:38 +0200 |
commit | 32a4ea350ee0bbbc1b1a941391626b53e4894920 (patch) | |
tree | f434e25770dcc33d5d71ab0767966ba996006e0d /searx/engines/bing_images.py | |
parent | 079636c0795aafed9306703a4decdc92447ed57f (diff) | |
download | searxng-32a4ea350ee0bbbc1b1a941391626b53e4894920.tar.gz searxng-32a4ea350ee0bbbc1b1a941391626b53e4894920.zip |
[fix] Revision of the Bing engines
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines/bing_images.py')
-rw-r--r-- | searx/engines/bing_images.py | 40 |
1 files changed, 10 insertions, 30 deletions
diff --git a/searx/engines/bing_images.py b/searx/engines/bing_images.py index 25b4e4f41..faf0941c8 100644 --- a/searx/engines/bing_images.py +++ b/searx/engines/bing_images.py @@ -12,15 +12,14 @@ from urllib.parse import urlencode from lxml import html from searx.enginelib.traits import EngineTraits -from searx.engines.bing import ( - set_bing_cookies, - _fetch_traits, -) +from searx.engines.bing import set_bing_cookies +from searx.engines.bing import fetch_traits # pylint: disable=unused-import + if TYPE_CHECKING: import logging - logger: logging.Logger + logger = logging.getLogger() traits: EngineTraits @@ -43,38 +42,29 @@ time_range_support = True base_url = 'https://www.bing.com/images/async' """Bing (Images) search URL""" -bing_traits_url = 'https://learn.microsoft.com/en-us/bing/search-apis/bing-image-search/reference/market-codes' -"""Bing (Images) search API description""" - time_map = { - # fmt: off 'day': 60 * 24, 'week': 60 * 24 * 7, 'month': 60 * 24 * 31, 'year': 60 * 24 * 365, - # fmt: on } def request(query, params): """Assemble a Bing-Image request.""" - engine_region = traits.get_region(params['searxng_locale'], 'en-us') - engine_language = traits.get_language(params['searxng_locale'], 'en-us') - + engine_region = traits.get_region(params['searxng_locale'], traits.all_locale) # type: ignore + engine_language = traits.get_language(params['searxng_locale'], 'en') # type: ignore set_bing_cookies(params, engine_language, engine_region) # build URL query - # - example: https://www.bing.com/images/async?q=foo&first=155&count=35 - + # - example: https://www.bing.com/images/async?q=foo&async=content&first=1&count=35 query_params = { - # fmt: off 'q': query, - 'async' : 'content', + 'async': '1', # to simplify the page count lets use the default of 35 images per page - 'first' : (int(params.get('pageno', 1)) - 1) * 35 + 1, - 'count' : 35, - # fmt: on + 'first': (int(params.get('pageno', 1)) - 1) * 35 + 1, + 'count': 35, } # time range @@ -117,13 +107,3 @@ def response(resp): } ) return results - - -def fetch_traits(engine_traits: EngineTraits): - """Fetch languages and regions from Bing-News.""" - - xpath_market_codes = '//table[1]/tbody/tr/td[3]' - # xpath_country_codes = '//table[2]/tbody/tr/td[2]' - xpath_language_codes = '//table[3]/tbody/tr/td[2]' - - _fetch_traits(engine_traits, bing_traits_url, xpath_language_codes, xpath_market_codes) |