From b034356825420507c9fb7ee2dc100676a88cf6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Sun, 11 Dec 2016 16:41:14 +0100 Subject: [PATCH] add year filter to engines with time range support && tests Following engines does not support "Last year": * Bing News * DeviantArt * DuckDuckGo * Yahoo * YouTube (noapi) --- searx/engines/bing_news.py | 3 +++ searx/engines/deviantart.py | 3 +++ searx/engines/duckduckgo.py | 3 +++ searx/engines/yahoo.py | 3 +++ searx/engines/youtube_noapi.py | 3 ++- tests/unit/engines/test_bing_news.py | 7 +++++++ tests/unit/engines/test_deviantart.py | 9 ++++++++- tests/unit/engines/test_duckduckgo.py | 7 +++++++ tests/unit/engines/test_yahoo.py | 7 +++++++ 9 files changed, 43 insertions(+), 2 deletions(-) diff --git a/searx/engines/bing_news.py b/searx/engines/bing_news.py index 906afe662..4e7c33129 100644 --- 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 index d893fc7fe..a24b75b8a 100644 --- 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 index 2153492e9..9959a52e6 100644 --- 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 index 8e24a283e..2bb34b83d 100644 --- 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 index b33594465..9b7ca64c8 100644 --- 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 = '