mirror of https://github.com/searxng/searxng.git
[fix] time range detection
This commit is contained in:
parent
3a8d193d1f
commit
350a84520d
|
@ -13,7 +13,6 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
from urlparse import urljoin
|
|
||||||
from lxml import html
|
from lxml import html
|
||||||
import re
|
import re
|
||||||
from searx.engines.xpath import extract_text
|
from searx.engines.xpath import extract_text
|
||||||
|
@ -39,7 +38,7 @@ def request(query, params):
|
||||||
|
|
||||||
params['url'] = search_url.format(offset=offset,
|
params['url'] = search_url.format(offset=offset,
|
||||||
query=urlencode({'q': query}))
|
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']])
|
params['url'] += time_range_url.format(range=time_range_dict[params['time_range']])
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
|
|
@ -67,7 +67,7 @@ def request(query, params):
|
||||||
params['url'] = url.format(
|
params['url'] = url.format(
|
||||||
query=urlencode({'q': query}), offset=offset)
|
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']])
|
params['url'] += time_range_url.format(range=time_range_dict[params['time_range']])
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
|
|
@ -185,7 +185,7 @@ def request(query, params):
|
||||||
query=urlencode({'q': query}),
|
query=urlencode({'q': query}),
|
||||||
hostname=google_hostname,
|
hostname=google_hostname,
|
||||||
lang=url_lang)
|
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['url'] += time_range_search.format(range=time_range_dict[params['time_range']])
|
||||||
|
|
||||||
params['headers']['Accept-Language'] = language
|
params['headers']['Accept-Language'] = language
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
from urlparse import parse_qs
|
|
||||||
from json import loads
|
from json import loads
|
||||||
from lxml import html
|
from lxml import html
|
||||||
|
|
||||||
|
@ -39,7 +38,7 @@ def request(query, params):
|
||||||
params['url'] = search_url.format(query=urlencode({'q': query}),
|
params['url'] = search_url.format(query=urlencode({'q': query}),
|
||||||
offset=offset,
|
offset=offset,
|
||||||
safesearch=safesearch)
|
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']])
|
params['url'] += time_range_search.format(range=time_range_dict[params['time_range']])
|
||||||
|
|
||||||
if safesearch and params['safesearch']:
|
if safesearch and params['safesearch']:
|
||||||
|
|
|
@ -58,7 +58,7 @@ def parse_url(url_string):
|
||||||
|
|
||||||
|
|
||||||
def _get_url(query, offset, language, time_range):
|
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,
|
return base_url + search_url_with_time.format(offset=offset,
|
||||||
query=urlencode({'p': query}),
|
query=urlencode({'p': query}),
|
||||||
lang=language,
|
lang=language,
|
||||||
|
|
|
@ -10,6 +10,7 @@ class TestDeviantartEngine(SearxTestCase):
|
||||||
query = 'test_query'
|
query = 'test_query'
|
||||||
dicto = defaultdict(dict)
|
dicto = defaultdict(dict)
|
||||||
dicto['pageno'] = 0
|
dicto['pageno'] = 0
|
||||||
|
dicto['time_range'] = ''
|
||||||
params = deviantart.request(query, dicto)
|
params = deviantart.request(query, dicto)
|
||||||
self.assertTrue('url' in params)
|
self.assertTrue('url' in params)
|
||||||
self.assertTrue(query in params['url'])
|
self.assertTrue(query in params['url'])
|
||||||
|
|
|
@ -12,6 +12,7 @@ class TestDuckduckgoEngine(SearxTestCase):
|
||||||
dicto = defaultdict(dict)
|
dicto = defaultdict(dict)
|
||||||
dicto['pageno'] = 1
|
dicto['pageno'] = 1
|
||||||
dicto['language'] = 'de_CH'
|
dicto['language'] = 'de_CH'
|
||||||
|
dicto['time_range'] = ''
|
||||||
params = duckduckgo.request(query, dicto)
|
params = duckduckgo.request(query, dicto)
|
||||||
self.assertIn('url', params)
|
self.assertIn('url', params)
|
||||||
self.assertIn(query, params['url'])
|
self.assertIn(query, params['url'])
|
||||||
|
|
|
@ -19,6 +19,7 @@ class TestGoogleEngine(SearxTestCase):
|
||||||
dicto = defaultdict(dict)
|
dicto = defaultdict(dict)
|
||||||
dicto['pageno'] = 1
|
dicto['pageno'] = 1
|
||||||
dicto['language'] = 'fr_FR'
|
dicto['language'] = 'fr_FR'
|
||||||
|
dicto['time_range'] = ''
|
||||||
params = google.request(query, dicto)
|
params = google.request(query, dicto)
|
||||||
self.assertIn('url', params)
|
self.assertIn('url', params)
|
||||||
self.assertIn(query, params['url'])
|
self.assertIn(query, params['url'])
|
||||||
|
|
|
@ -11,6 +11,7 @@ class TestGoogleImagesEngine(SearxTestCase):
|
||||||
dicto = defaultdict(dict)
|
dicto = defaultdict(dict)
|
||||||
dicto['pageno'] = 1
|
dicto['pageno'] = 1
|
||||||
dicto['safesearch'] = 1
|
dicto['safesearch'] = 1
|
||||||
|
dicto['time_range'] = ''
|
||||||
params = google_images.request(query, dicto)
|
params = google_images.request(query, dicto)
|
||||||
self.assertIn('url', params)
|
self.assertIn('url', params)
|
||||||
self.assertIn(query, params['url'])
|
self.assertIn(query, params['url'])
|
||||||
|
|
|
@ -28,6 +28,7 @@ class TestYahooEngine(SearxTestCase):
|
||||||
query = 'test_query'
|
query = 'test_query'
|
||||||
dicto = defaultdict(dict)
|
dicto = defaultdict(dict)
|
||||||
dicto['pageno'] = 1
|
dicto['pageno'] = 1
|
||||||
|
dicto['time_range'] = ''
|
||||||
dicto['language'] = 'fr_FR'
|
dicto['language'] = 'fr_FR'
|
||||||
params = yahoo.request(query, dicto)
|
params = yahoo.request(query, dicto)
|
||||||
self.assertIn('url', params)
|
self.assertIn('url', params)
|
||||||
|
|
Loading…
Reference in New Issue