From 350a84520d9da2499ffd5b0fbe6218692f2a330d Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Tue, 26 Jul 2016 00:22:05 +0200 Subject: [PATCH] [fix] time range detection --- searx/engines/deviantart.py | 3 +-- searx/engines/duckduckgo.py | 2 +- searx/engines/google.py | 2 +- searx/engines/google_images.py | 3 +-- searx/engines/yahoo.py | 2 +- tests/unit/engines/test_deviantart.py | 1 + tests/unit/engines/test_duckduckgo.py | 1 + tests/unit/engines/test_google.py | 1 + tests/unit/engines/test_google_images.py | 1 + tests/unit/engines/test_yahoo.py | 1 + 10 files changed, 10 insertions(+), 7 deletions(-) diff --git a/searx/engines/deviantart.py b/searx/engines/deviantart.py index ef1dd9e5f..d893fc7fe 100644 --- a/searx/engines/deviantart.py +++ b/searx/engines/deviantart.py @@ -13,7 +13,6 @@ """ from urllib import urlencode -from urlparse import urljoin from lxml import html import re from searx.engines.xpath import extract_text @@ -39,7 +38,7 @@ def request(query, params): params['url'] = search_url.format(offset=offset, query=urlencode({'q': query})) - if params['time_range']: + if params['time_range'] in time_range_dict: params['url'] += time_range_url.format(range=time_range_dict[params['time_range']]) return params diff --git a/searx/engines/duckduckgo.py b/searx/engines/duckduckgo.py index aa7a98754..2153492e9 100644 --- a/searx/engines/duckduckgo.py +++ b/searx/engines/duckduckgo.py @@ -67,7 +67,7 @@ def request(query, params): params['url'] = url.format( query=urlencode({'q': query}), offset=offset) - if params['time_range']: + if params['time_range'] in time_range_dict: params['url'] += time_range_url.format(range=time_range_dict[params['time_range']]) return params diff --git a/searx/engines/google.py b/searx/engines/google.py index 3b845cbcd..ea93bc94f 100644 --- a/searx/engines/google.py +++ b/searx/engines/google.py @@ -185,7 +185,7 @@ def request(query, params): query=urlencode({'q': query}), hostname=google_hostname, lang=url_lang) - if params['time_range']: + if params['time_range'] in time_range_dict: params['url'] += time_range_search.format(range=time_range_dict[params['time_range']]) params['headers']['Accept-Language'] = language diff --git a/searx/engines/google_images.py b/searx/engines/google_images.py index b687317c8..090d44704 100644 --- a/searx/engines/google_images.py +++ b/searx/engines/google_images.py @@ -11,7 +11,6 @@ """ from urllib import urlencode -from urlparse import parse_qs from json import loads from lxml import html @@ -39,7 +38,7 @@ def request(query, params): params['url'] = search_url.format(query=urlencode({'q': query}), offset=offset, safesearch=safesearch) - if params['time_range']: + if params['time_range'] in time_range_dict: params['url'] += time_range_search.format(range=time_range_dict[params['time_range']]) if safesearch and params['safesearch']: diff --git a/searx/engines/yahoo.py b/searx/engines/yahoo.py index 82f782b9d..8e24a283e 100644 --- a/searx/engines/yahoo.py +++ b/searx/engines/yahoo.py @@ -58,7 +58,7 @@ def parse_url(url_string): def _get_url(query, offset, language, time_range): - if time_range: + if time_range in time_range_dict: return base_url + search_url_with_time.format(offset=offset, query=urlencode({'p': query}), lang=language, diff --git a/tests/unit/engines/test_deviantart.py b/tests/unit/engines/test_deviantart.py index c00bb8fab..75c59f760 100644 --- a/tests/unit/engines/test_deviantart.py +++ b/tests/unit/engines/test_deviantart.py @@ -10,6 +10,7 @@ class TestDeviantartEngine(SearxTestCase): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 0 + dicto['time_range'] = '' params = deviantart.request(query, dicto) self.assertTrue('url' in params) self.assertTrue(query in params['url']) diff --git a/tests/unit/engines/test_duckduckgo.py b/tests/unit/engines/test_duckduckgo.py index 90cdc9d9e..cb866d396 100644 --- a/tests/unit/engines/test_duckduckgo.py +++ b/tests/unit/engines/test_duckduckgo.py @@ -12,6 +12,7 @@ class TestDuckduckgoEngine(SearxTestCase): dicto = defaultdict(dict) dicto['pageno'] = 1 dicto['language'] = 'de_CH' + dicto['time_range'] = '' params = duckduckgo.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) diff --git a/tests/unit/engines/test_google.py b/tests/unit/engines/test_google.py index 37a83cae3..8e73e2ab7 100644 --- a/tests/unit/engines/test_google.py +++ b/tests/unit/engines/test_google.py @@ -19,6 +19,7 @@ class TestGoogleEngine(SearxTestCase): dicto = defaultdict(dict) dicto['pageno'] = 1 dicto['language'] = 'fr_FR' + dicto['time_range'] = '' params = google.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) diff --git a/tests/unit/engines/test_google_images.py b/tests/unit/engines/test_google_images.py index 5f184e00c..1cfba60b3 100644 --- a/tests/unit/engines/test_google_images.py +++ b/tests/unit/engines/test_google_images.py @@ -11,6 +11,7 @@ class TestGoogleImagesEngine(SearxTestCase): dicto = defaultdict(dict) dicto['pageno'] = 1 dicto['safesearch'] = 1 + dicto['time_range'] = '' params = google_images.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) diff --git a/tests/unit/engines/test_yahoo.py b/tests/unit/engines/test_yahoo.py index 11ef9db22..1226f92ab 100644 --- a/tests/unit/engines/test_yahoo.py +++ b/tests/unit/engines/test_yahoo.py @@ -28,6 +28,7 @@ class TestYahooEngine(SearxTestCase): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 1 + dicto['time_range'] = '' dicto['language'] = 'fr_FR' params = yahoo.request(query, dicto) self.assertIn('url', params)