logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://hacktivis.me/git/searx.git
commit: f70d405202ccec44849f8cd8d30ba37b254f2b69
parent e3d748ded435aad8f1b11a4870011ae52e7c838f
Author: Noémi Ványi <sitbackandwait@gmail.com>
Date:   Sun, 30 Oct 2016 18:14:42 +0100

add time range search for bing news

Diffstat:

Msearx/engines/bing_news.py24+++++++++++++++++++-----
Mtests/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 @@ -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 @@ -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'])