summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-07-25 10:30:41 +0200
committerGitHub <noreply@github.com>2021-07-25 10:30:41 +0200
commitcb4220657c38b2909d16f01a5ff0ae0debcc18a7 (patch)
tree7eeb0810b9f0f03c1df42b7e680a0e77180a637f
parentea0f4346b13527c601bfcfb1f5d17a13b3dfc15c (diff)
parentfe67f1478f2f6b0939f378e7a1c65b7303f35763 (diff)
downloadsearxng-cb4220657c38b2909d16f01a5ff0ae0debcc18a7.tar.gz
searxng-cb4220657c38b2909d16f01a5ff0ae0debcc18a7.zip
Merge pull request #223 from return42/fix-qwant
[fix] qwant engine - hardening the engine
-rw-r--r--searx/engines/qwant.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/searx/engines/qwant.py b/searx/engines/qwant.py
index 97e461177..8d03d8324 100644
--- a/searx/engines/qwant.py
+++ b/searx/engines/qwant.py
@@ -84,14 +84,16 @@ def request(query, params):
)
# add language tag
- if params['language'] != 'all':
+ if params['language'] == 'all':
+ params['url'] += '&locale=en_us'
+ else:
language = match_language(
params['language'],
# pylint: disable=undefined-variable
supported_languages,
language_aliases,
)
- params['url'] += '&locale=' + language.replace('-', '_')
+ params['url'] += '&locale=' + language.replace('-', '_').lower()
params['raise_for_httperror'] = False
return params
@@ -144,8 +146,8 @@ def response(resp):
mainline_items = row.get('items', [])
for item in mainline_items:
- title = item['title']
- res_url = item['url']
+ title = item.get('title', None)
+ res_url = item.get('url', None)
if mainline_type == 'web':
content = item['desc']
@@ -156,7 +158,10 @@ def response(resp):
})
elif mainline_type == 'news':
- pub_date = datetime.fromtimestamp(item['date'], None)
+
+ pub_date = item['date']
+ if pub_date is not None:
+ pub_date = datetime.fromtimestamp(pub_date)
news_media = item.get('media', [])
img_src = None
if news_media:
@@ -192,8 +197,12 @@ def response(resp):
if c:
content_parts.append("%s: %s " % (gettext("Channel"), c))
content = ' // '.join(content_parts)
- length = timedelta(seconds=item['duration'])
- pub_date = datetime.fromtimestamp(item['date'])
+ length = item['duration']
+ if length is not None:
+ length = timedelta(milliseconds=length)
+ pub_date = item['date']
+ if pub_date is not None:
+ pub_date = datetime.fromtimestamp(pub_date)
thumbnail = item['thumbnail']
# from some locations (DE and others?) the s2 link do
# response a 'Please wait ..' but does not deliver the thumbnail