summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoémi Ványi <sitbackandwait@gmail.com>2016-10-30 18:14:42 +0100
committerNoémi Ványi <sitbackandwait@gmail.com>2016-11-01 17:58:29 +0100
commitf70d405202ccec44849f8cd8d30ba37b254f2b69 (patch)
treefbf4af78a1b38fe5d1bf3f08d3ec90a851f85c97
parente3d748ded435aad8f1b11a4870011ae52e7c838f (diff)
downloadsearxng-f70d405202ccec44849f8cd8d30ba37b254f2b69.tar.gz
searxng-f70d405202ccec44849f8cd8d30ba37b254f2b69.zip
add time range search for bing news
-rw-r--r--searx/engines/bing_news.py24
-rw-r--r--tests/unit/engines/test_bing_news.py1
2 files changed, 20 insertions, 5 deletions
diff --git a/searx/engines/bing_news.py b/searx/engines/bing_news.py
index a2397c48e..906afe662 100644
--- a/searx/engines/bing_news.py
+++ b/searx/engines/bing_news.py
@@ -22,10 +22,15 @@ from searx.utils import list_get
categories = ['news']
paging = True
language_support = True
+time_range_support = True
# search-url
base_url = 'https://www.bing.com/'
search_string = 'news/search?{query}&first={offset}&format=RSS'
+search_string_with_time = 'news/search?{query}&first={offset}&qft=interval%3d"{interval}"&format=RSS'
+time_range_dict = {'day': '7',
+ 'week': '8',
+ 'month': '9'}
# remove click
@@ -46,6 +51,19 @@ def image_url_cleanup(url_string):
return url_string
+def _get_url(query, language, offset, time_range):
+ if time_range in time_range_dict:
+ search_path = search_string_with_time.format(
+ query=urlencode({'q': query, 'setmkt': language}),
+ offset=offset,
+ interval=time_range_dict[time_range])
+ else:
+ search_path = search_string.format(
+ query=urlencode({'q': query, 'setmkt': language}),
+ offset=offset)
+ return base_url + search_path
+
+
# do search-request
def request(query, params):
offset = (params['pageno'] - 1) * 10 + 1
@@ -55,11 +73,7 @@ def request(query, params):
else:
language = params['language'].replace('_', '-')
- search_path = search_string.format(
- query=urlencode({'q': query, 'setmkt': language}),
- offset=offset)
-
- params['url'] = base_url + search_path
+ params['url'] = _get_url(query, language, offset, params['time_range'])
return params
diff --git a/tests/unit/engines/test_bing_news.py b/tests/unit/engines/test_bing_news.py
index a64d59b7b..a909defec 100644
--- a/tests/unit/engines/test_bing_news.py
+++ b/tests/unit/engines/test_bing_news.py
@@ -12,6 +12,7 @@ class TestBingNewsEngine(SearxTestCase):
dicto = defaultdict(dict)
dicto['pageno'] = 1
dicto['language'] = 'fr_FR'
+ dicto['time_range'] = ''
params = bing_news.request(query, dicto)
self.assertIn('url', params)
self.assertIn(query, params['url'])