From e3d748ded435aad8f1b11a4870011ae52e7c838f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Sun, 30 Oct 2016 20:49:45 +0100 Subject: [PATCH 1/5] show time range support in preferences --- searx/templates/oscar/preferences.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/searx/templates/oscar/preferences.html b/searx/templates/oscar/preferences.html index 283b7ba88..85e90d17d 100644 --- a/searx/templates/oscar/preferences.html +++ b/searx/templates/oscar/preferences.html @@ -158,6 +158,7 @@ {{ _("Engine name") }} {{ _("Shortcut") }} {{ _("SafeSearch") }} + {{ _("Time range") }} {{ _("Avg. time") }} {{ _("Max time") }} {% else %} @@ -179,6 +180,7 @@ {{ search_engine.name }} {{ shortcuts[search_engine.name] }} + {{ 'N/A' if stats[search_engine.name].time==None else stats[search_engine.name].time }} {{ search_engine.timeout }} {% else %} From f70d405202ccec44849f8cd8d30ba37b254f2b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Sun, 30 Oct 2016 18:14:42 +0100 Subject: [PATCH 2/5] add time range search for bing news --- searx/engines/bing_news.py | 24 +++++++++++++++++++----- tests/unit/engines/test_bing_news.py | 1 + 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']) From d2e0cbafb265594a23389fe58b7889ff088560f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Sun, 30 Oct 2016 20:26:38 +0100 Subject: [PATCH 3/5] add time range search for youtube noapi --- searx/engines/youtube_noapi.py | 7 +++++++ tests/unit/engines/test_youtube_noapi.py | 1 + 2 files changed, 8 insertions(+) diff --git a/searx/engines/youtube_noapi.py b/searx/engines/youtube_noapi.py index 401fca4c9..b33594465 100644 --- a/searx/engines/youtube_noapi.py +++ b/searx/engines/youtube_noapi.py @@ -17,10 +17,15 @@ from searx.utils import list_get categories = ['videos', 'music'] paging = True language_support = False +time_range_support = True # search-url base_url = 'https://www.youtube.com/results' 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'} embedded_url = '