diff options
author | Noémi Ványi <sitbackandwait@gmail.com> | 2016-10-30 21:20:40 +0100 |
---|---|---|
committer | Noémi Ványi <sitbackandwait@gmail.com> | 2016-11-01 17:58:29 +0100 |
commit | 1490d6bc939a59458a6ae9a56045064a3fc8b7a4 (patch) | |
tree | 87547b424edec417b3306e84c92bae1af5ede295 /searx/engines | |
parent | 5c02b9ef3113feaf8e98621970f7836a74376c23 (diff) | |
download | searxng-1490d6bc939a59458a6ae9a56045064a3fc8b7a4.tar.gz searxng-1490d6bc939a59458a6ae9a56045064a3fc8b7a4.zip |
add time range search for flickr
Diffstat (limited to 'searx/engines')
-rw-r--r-- | searx/engines/flickr_noapi.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/searx/engines/flickr_noapi.py b/searx/engines/flickr_noapi.py index 87b912eb3..5c4193c11 100644 --- a/searx/engines/flickr_noapi.py +++ b/searx/engines/flickr_noapi.py @@ -14,6 +14,7 @@ from urllib import urlencode from json import loads +from time import time import re from searx.engines import logger @@ -24,21 +25,31 @@ categories = ['images'] url = 'https://www.flickr.com/' 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}' 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') 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): return photo_url.format(userid=user_id, photoid=photo_id) -def request(query, params): - params['url'] = search_url.format(query=urlencode({'text': query}), - page=params['pageno']) +def _get_time_range_url(time_range): + if time_range in time_range_dict: + 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 |