SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
[mod] engine: bing images - use internal API & type hints (#6699)
Markus Heiser56b1f64541ff
diff --git a/searx/engines/bing_images.py b/searx/engines/bing_images.pyindex b39fd0935..989adba06 100644--- a/searx/engines/bing_images.py+++ b/searx/engines/bing_images.py@@ -1,14 +1,20 @@# SPDX-License-Identifier: AGPL-3.0-or-later"""Bing-Images: description see :py:obj:`searx.engines.bing`."""+import typing as timport jsonfrom urllib.parse import urlencodefrom lxml import htmlfrom searx.engines.bing import fetch_traits # pylint: disable=unused-import+from searx.result_types import EngineResults++if t.TYPE_CHECKING:+ from searx.extended_types import SXNG_Response+ from searx.search.processors import OnlineParams+-# aboutabout = {"website": "https://www.bing.com/images","wikidata_id": "Q182496",@@ -18,7 +24,6 @@ about = {"results": "HTML",}-# engine dependent configcategories = ["images", "web"]paging = Trueenable_http3 = True@@ -35,13 +40,13 @@ base_url = "https://www.bing.com""""Bing-Image search URL"""-def request(query, params):+def request(query: str, params: "OnlineParams"):"""Assemble a Bing-Image request."""engine_region = traits.get_region(params["searxng_locale"], traits.all_locale)- # build URL query- # - example: https://www.bing.com/images/async?q=foo&mmasync=1&first=1&count=35+ # build URL query / example:+ # https://www.bing.com/images/async?q=foo&mmasync=1&first=1&count=35query_params = {"q": query,@@ -65,10 +70,10 @@ def request(query, params):params["url"] = base_url + "/images/async?" + urlencode(query_params)-def response(resp):+def response(resp: "SXNG_Response") -> EngineResults:"""Get response from Bing-Image"""- results = []+ res = EngineResults()dom = html.fromstring(resp.text)@@ -84,17 +89,17 @@ def response(resp):img_format = " ".join(result.xpath('.//div[@class="imgpt"]/div/span/text()')).strip().split(" · ")source = " ".join(result.xpath('.//div[@class="imgpt"]//div[@class="lnkw"]//a/text()')).strip()- results.append(- {- "template": "images.html",- "url": metadata["purl"],- "thumbnail_src": metadata["turl"],- "img_src": metadata["murl"],- "content": metadata.get("desc"),- "title": title,- "source": source,- "resolution": img_format[0],- "img_format": img_format[1] if len(img_format) >= 2 else None,- }++ res.add(+ res.types.Image(+ title=title,+ url=metadata["purl"],+ thumbnail_src=metadata["turl"],+ img_src=metadata["murl"],+ content=metadata.get("desc"),+ source=source,+ resolution=img_format[0],+ img_format=img_format[1] if len(img_format) >= 2 else "",+ ))- return results+ return res