add time range search for bing news

This commit is contained in:
Noémi Ványi 2016-10-30 18:14:42 +01:00
parent e3d748ded4
commit f70d405202
2 changed files with 20 additions and 5 deletions

View File

@ -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

View File

@ -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'])