summaryrefslogtreecommitdiff
path: root/searx/engines/bing_news.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2022-10-15 21:17:39 +0200
committerMarkus Heiser <markus.heiser@darmarit.de>2023-03-24 10:37:42 +0100
commitd0f465e6fa364805bcc7848d22860068c0a27be4 (patch)
treee4912369351a05eeaa0b68925bbf585986e469a3 /searx/engines/bing_news.py
parentc9cd376186d12d2d281e655d0b5539d1359fe148 (diff)
downloadsearxng-d0f465e6fa364805bcc7848d22860068c0a27be4.tar.gz
searxng-d0f465e6fa364805bcc7848d22860068c0a27be4.zip
[mod] bing: add time_range support & upgrade to data_type: traits_v1
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines/bing_news.py')
-rw-r--r--searx/engines/bing_news.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/searx/engines/bing_news.py b/searx/engines/bing_news.py
index 8a5f70259..680e47538 100644
--- a/searx/engines/bing_news.py
+++ b/searx/engines/bing_news.py
@@ -14,12 +14,7 @@ from dateutil import parser
from lxml import etree
from lxml.etree import XPath
from searx.utils import match_language, eval_xpath_getindex
-from searx.engines.bing import ( # pylint: disable=unused-import
- language_aliases,
- _fetch_supported_languages,
- fetch_traits,
- supported_languages_url,
-)
+from searx.enginelib.traits import EngineTraits
# about
about = {
@@ -140,3 +135,21 @@ def response(resp):
results.append({'url': url, 'title': title, 'publishedDate': publishedDate, 'content': content})
return results
+
+
+def fetch_traits(engine_traits: EngineTraits):
+ """Fetch languages and regions from Bing-News."""
+ # pylint: disable=import-outside-toplevel
+
+ from searx.engines.bing import _fetch_traits
+
+ url = 'https://learn.microsoft.com/en-us/bing/search-apis/bing-news-search/reference/market-codes'
+
+ # The description of the first table says "query parameter when calling the
+ # Video Search API." .. thats why I use the 4. table "News Category API markets"
+ xpath_market_codes = '//table[4]/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, url, xpath_language_codes, xpath_market_codes)