mirror of https://github.com/searxng/searxng.git
add time range search for flickr
This commit is contained in:
parent
5c02b9ef31
commit
1490d6bc93
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
from json import loads
|
from json import loads
|
||||||
|
from time import time
|
||||||
import re
|
import re
|
||||||
from searx.engines import logger
|
from searx.engines import logger
|
||||||
|
|
||||||
|
@ -24,21 +25,31 @@ categories = ['images']
|
||||||
|
|
||||||
url = 'https://www.flickr.com/'
|
url = 'https://www.flickr.com/'
|
||||||
search_url = url + 'search?{query}&page={page}'
|
search_url = url + 'search?{query}&page={page}'
|
||||||
|
time_range_url = '&min_upload_date={start}&max_upload_date={end}'
|
||||||
photo_url = 'https://www.flickr.com/photos/{userid}/{photoid}'
|
photo_url = 'https://www.flickr.com/photos/{userid}/{photoid}'
|
||||||
regex = re.compile(r"\"search-photos-lite-models\",\"photos\":(.*}),\"totalItems\":", re.DOTALL)
|
regex = re.compile(r"\"search-photos-lite-models\",\"photos\":(.*}),\"totalItems\":", re.DOTALL)
|
||||||
image_sizes = ('o', 'k', 'h', 'b', 'c', 'z', 'n', 'm', 't', 'q', 's')
|
image_sizes = ('o', 'k', 'h', 'b', 'c', 'z', 'n', 'm', 't', 'q', 's')
|
||||||
|
|
||||||
paging = True
|
paging = True
|
||||||
|
time_range_support = True
|
||||||
|
time_range_dict = {'day': 60 * 60 * 24,
|
||||||
|
'week': 60 * 60 * 24 * 7,
|
||||||
|
'month': 60 * 60 * 24 * 7 * 4}
|
||||||
|
|
||||||
|
|
||||||
def build_flickr_url(user_id, photo_id):
|
def build_flickr_url(user_id, photo_id):
|
||||||
return photo_url.format(userid=user_id, photoid=photo_id)
|
return photo_url.format(userid=user_id, photoid=photo_id)
|
||||||
|
|
||||||
|
|
||||||
def request(query, params):
|
def _get_time_range_url(time_range):
|
||||||
params['url'] = search_url.format(query=urlencode({'text': query}),
|
if time_range in time_range_dict:
|
||||||
page=params['pageno'])
|
return time_range_url.format(start=time(), end=str(int(time()) - time_range_dict[time_range]))
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
def request(query, params):
|
||||||
|
params['url'] = (search_url.format(query=urlencode({'text': query}), page=params['pageno'])
|
||||||
|
+ _get_time_range_url(params['time_range']))
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ class TestFlickrNoapiEngine(SearxTestCase):
|
||||||
query = 'test_query'
|
query = 'test_query'
|
||||||
dicto = defaultdict(dict)
|
dicto = defaultdict(dict)
|
||||||
dicto['pageno'] = 1
|
dicto['pageno'] = 1
|
||||||
|
dicto['time_range'] = ''
|
||||||
params = flickr_noapi.request(query, dicto)
|
params = flickr_noapi.request(query, dicto)
|
||||||
self.assertIn('url', params)
|
self.assertIn('url', params)
|
||||||
self.assertIn(query, params['url'])
|
self.assertIn(query, params['url'])
|
||||||
|
|
Loading…
Reference in New Issue