summaryrefslogtreecommitdiff
path: root/searx/engines/google_images.py
diff options
context:
space:
mode:
authorAdam Tauber <asciimoo@gmail.com>2016-12-12 10:06:43 +0100
committerGitHub <noreply@github.com>2016-12-12 10:06:43 +0100
commite58949b76fac7aa93341523ff0e2f35e0a03e057 (patch)
tree82f90b1e406ffda0276d2918b1b86c3589e50012 /searx/engines/google_images.py
parent6b6007fc78f47099d84099c6d6c23e2cd213b82f (diff)
parentb034356825420507c9fb7ee2dc100676a88cf6c7 (diff)
Merge pull request #783 from kvch/time-range-search-year
add year support to engines which support it
Diffstat (limited to 'searx/engines/google_images.py')
-rw-r--r--searx/engines/google_images.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/searx/engines/google_images.py b/searx/engines/google_images.py
index 77bdc13b2..9a3c71c7e 100644
--- a/searx/engines/google_images.py
+++ b/searx/engines/google_images.py
@@ -10,10 +10,12 @@
@parse url, title, img_src
"""
+from datetime import date, timedelta
from urllib import urlencode
from json import loads
from lxml import html
+
# engine dependent config
categories = ['images']
paging = True
@@ -29,6 +31,7 @@ search_url = 'https://www.google.com/search'\
'&yv=2'\
'&{search_options}'
time_range_attr = "qdr:{range}"
+time_range_custom_attr = "cdr:1,cd_min:{start},cd_max{end}"
time_range_dict = {'day': 'd',
'week': 'w',
'month': 'm'}
@@ -36,7 +39,6 @@ time_range_dict = {'day': 'd',
# do search-request
def request(query, params):
-
search_options = {
'ijn': params['pageno'] - 1,
'start': (params['pageno'] - 1) * number_of_results
@@ -44,6 +46,12 @@ def request(query, params):
if params['time_range'] in time_range_dict:
search_options['tbs'] = time_range_attr.format(range=time_range_dict[params['time_range']])
+ elif params['time_range'] == 'year':
+ now = date.today()
+ then = now - timedelta(days=365)
+ start = then.strftime('%m/%d/%Y')
+ end = now.strftime('%m/%d/%Y')
+ search_options['tbs'] = time_range_custom_attr.format(start=start, end=end)
if safesearch and params['safesearch']:
search_options['safe'] = 'on'