summaryrefslogtreecommitdiff
path: root/searx/engines/bing_news.py
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2020-11-26 15:38:07 +0100
committerAlexandre Flament <alex@al-f.net>2020-12-03 10:22:48 +0100
commitde887c6347db4c810f7d1e11c77633340d4e2fbd (patch)
treeb052c3cfc7f50f8649fb3df79f709306930885c4 /searx/engines/bing_news.py
parent1d0c368746e0ae28ea042edaf4c75ee3a2b738c2 (diff)
downloadsearxng-de887c6347db4c810f7d1e11c77633340d4e2fbd.tar.gz
searxng-de887c6347db4c810f7d1e11c77633340d4e2fbd.zip
[mod] bing_news: use eval_xpath_getindex
remove unused function searx.utils.list_get
Diffstat (limited to 'searx/engines/bing_news.py')
-rw-r--r--searx/engines/bing_news.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/searx/engines/bing_news.py b/searx/engines/bing_news.py
index 5489c7549..b95def48b 100644
--- a/searx/engines/bing_news.py
+++ b/searx/engines/bing_news.py
@@ -15,7 +15,8 @@ from datetime import datetime
from dateutil import parser
from urllib.parse import urlencode, urlparse, parse_qsl
from lxml import etree
-from searx.utils import list_get, match_language
+from lxml.etree import XPath
+from searx.utils import match_language, eval_xpath_getindex
from searx.engines.bing import language_aliases
from searx.engines.bing import _fetch_supported_languages, supported_languages_url # NOQA # pylint: disable=unused-import
@@ -94,12 +95,12 @@ def response(resp):
# parse results
for item in rss.xpath('./channel/item'):
# url / title / content
- url = url_cleanup(item.xpath('./link/text()')[0])
- title = list_get(item.xpath('./title/text()'), 0, url)
- content = list_get(item.xpath('./description/text()'), 0, '')
+ url = url_cleanup(eval_xpath_getindex(item, './link/text()', 0, default=None))
+ title = eval_xpath_getindex(item, './title/text()', 0, default=url)
+ content = eval_xpath_getindex(item, './description/text()', 0, default='')
# publishedDate
- publishedDate = list_get(item.xpath('./pubDate/text()'), 0)
+ publishedDate = eval_xpath_getindex(item, './pubDate/text()', 0, default=None)
try:
publishedDate = parser.parse(publishedDate, dayfirst=False)
except TypeError:
@@ -108,7 +109,7 @@ def response(resp):
publishedDate = datetime.now()
# thumbnail
- thumbnail = list_get(item.xpath('./News:Image/text()', namespaces=ns), 0)
+ thumbnail = eval_xpath_getindex(item, XPath('./News:Image/text()', namespaces=ns), 0, default=None)
if thumbnail is not None:
thumbnail = image_url_cleanup(thumbnail)