logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://hacktivis.me/git/searx.git
commit: b034356825420507c9fb7ee2dc100676a88cf6c7
parent c59c76e6ee14f0417ad55ecf0f888f62f34f1f6d
Author: Noémi Ványi <sitbackandwait@gmail.com>
Date:   Sun, 11 Dec 2016 16:41:14 +0100

add year filter to engines with time range support && tests

Following engines does not support "Last year":
 * Bing News
 * DeviantArt
 * DuckDuckGo
 * Yahoo
 * YouTube (noapi)

Diffstat:

Msearx/engines/bing_news.py3+++
Msearx/engines/deviantart.py3+++
Msearx/engines/duckduckgo.py3+++
Msearx/engines/yahoo.py3+++
Msearx/engines/youtube_noapi.py3++-
Mtests/unit/engines/test_bing_news.py7+++++++
Mtests/unit/engines/test_deviantart.py9++++++++-
Mtests/unit/engines/test_duckduckgo.py7+++++++
Mtests/unit/engines/test_yahoo.py7+++++++
9 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/searx/engines/bing_news.py b/searx/engines/bing_news.py @@ -66,6 +66,9 @@ def _get_url(query, language, offset, time_range): # do search-request def request(query, params): + if params['time_range'] and params['time_range'] not in time_range_dict: + return params + offset = (params['pageno'] - 1) * 10 + 1 if params['language'] == 'all': diff --git a/searx/engines/deviantart.py b/searx/engines/deviantart.py @@ -34,6 +34,9 @@ time_range_dict = {'day': 11, # do search-request def request(query, params): + if params['time_range'] and params['time_range'] not in time_range_dict: + return params + offset = (params['pageno'] - 1) * 24 params['url'] = search_url.format(offset=offset, diff --git a/searx/engines/duckduckgo.py b/searx/engines/duckduckgo.py @@ -41,6 +41,9 @@ content_xpath = './/a[@class="result__snippet"]' # do search-request def request(query, params): + if params['time_range'] and params['time_range'] not in time_range_dict: + return params + offset = (params['pageno'] - 1) * 30 if params['language'] == 'all': diff --git a/searx/engines/yahoo.py b/searx/engines/yahoo.py @@ -77,6 +77,9 @@ def _get_language(params): # do search-request def request(query, params): + if params['time_range'] and params['time_range'] not in time_range_dict: + return params + offset = (params['pageno'] - 1) * 10 + 1 language = _get_language(params) diff --git a/searx/engines/youtube_noapi.py b/searx/engines/youtube_noapi.py @@ -25,7 +25,8 @@ search_url = base_url + '?search_query={query}&page={page}' time_range_url = '&sp=EgII{time_range}%253D%253D' time_range_dict = {'day': 'Ag', 'week': 'Aw', - 'month': 'BA'} + 'month': 'BA', + 'year': 'BQ'} embedded_url = '<iframe width="540" height="304" ' +\ 'data-src="//www.youtube-nocookie.com/embed/{videoid}" ' +\ diff --git a/tests/unit/engines/test_bing_news.py b/tests/unit/engines/test_bing_news.py @@ -23,6 +23,13 @@ class TestBingNewsEngine(SearxTestCase): params = bing_news.request(query, dicto) self.assertIn('en', params['url']) + def test_no_url_in_request_year_time_range(self): + dicto = defaultdict(dict) + query = 'test_query' + dicto['time_range'] = 'year' + params = bing_news.request(query, dicto) + self.assertEqual({}, params['url']) + def test_response(self): self.assertRaises(AttributeError, bing_news.response, None) self.assertRaises(AttributeError, bing_news.response, []) diff --git a/tests/unit/engines/test_deviantart.py b/tests/unit/engines/test_deviantart.py @@ -7,8 +7,8 @@ from searx.testing import SearxTestCase class TestDeviantartEngine(SearxTestCase): def test_request(self): - query = 'test_query' dicto = defaultdict(dict) + query = 'test_query' dicto['pageno'] = 0 dicto['time_range'] = '' params = deviantart.request(query, dicto) @@ -16,6 +16,13 @@ class TestDeviantartEngine(SearxTestCase): self.assertTrue(query in params['url']) self.assertTrue('deviantart.com' in params['url']) + def test_no_url_in_request_year_time_range(self): + dicto = defaultdict(dict) + query = 'test_query' + dicto['time_range'] = 'year' + params = deviantart.request(query, dicto) + self.assertEqual({}, params['url']) + def test_response(self): self.assertRaises(AttributeError, deviantart.response, None) self.assertRaises(AttributeError, deviantart.response, []) diff --git a/tests/unit/engines/test_duckduckgo.py b/tests/unit/engines/test_duckduckgo.py @@ -19,6 +19,13 @@ class TestDuckduckgoEngine(SearxTestCase): self.assertIn('duckduckgo.com', params['url']) self.assertIn('ch-de', params['url']) + def test_no_url_in_request_year_time_range(self): + dicto = defaultdict(dict) + query = 'test_query' + dicto['time_range'] = 'year' + params = duckduckgo.request(query, dicto) + self.assertEqual({}, params['url']) + def test_response(self): self.assertRaises(AttributeError, duckduckgo.response, None) self.assertRaises(AttributeError, duckduckgo.response, []) diff --git a/tests/unit/engines/test_yahoo.py b/tests/unit/engines/test_yahoo.py @@ -46,6 +46,13 @@ class TestYahooEngine(SearxTestCase): self.assertIn('en', params['cookies']['sB']) self.assertIn('en', params['url']) + def test_no_url_in_request_year_time_range(self): + dicto = defaultdict(dict) + query = 'test_query' + dicto['time_range'] = 'year' + params = yahoo.request(query, dicto) + self.assertEqual({}, params['url']) + def test_response(self): self.assertRaises(AttributeError, yahoo.response, None) self.assertRaises(AttributeError, yahoo.response, [])