summaryrefslogtreecommitdiff
path: root/searx/engines/google_images.py
diff options
context:
space:
mode:
authorThomas Pointhuber <thomas.pointhuber@gmx.at>2014-09-01 15:10:05 +0200
committerThomas Pointhuber <thomas.pointhuber@gmx.at>2014-09-01 15:10:05 +0200
commit144f89bf785408a193d09f659a5442032c06de74 (patch)
treebd4a3936e82ab2bde8b4d1be709e4988c2e6bfbe /searx/engines/google_images.py
parentcdf74fe563f24facec5bb487b5b3c6f599b08934 (diff)
downloadsearxng-144f89bf785408a193d09f659a5442032c06de74.tar.gz
searxng-144f89bf785408a193d09f659a5442032c06de74.zip
add comments to google-engines
Diffstat (limited to 'searx/engines/google_images.py')
-rw-r--r--searx/engines/google_images.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/searx/engines/google_images.py b/searx/engines/google_images.py
index e810ee07d..6c99f2801 100644
--- a/searx/engines/google_images.py
+++ b/searx/engines/google_images.py
@@ -1,37 +1,58 @@
-#!/usr/bin/env python
+## Google (Images)
+#
+# @website https://www.google.com
+# @provide-api yes (https://developers.google.com/web-search/docs/), deprecated!
+#
+# @using-api yes
+# @results JSON
+# @stable yes (but deprecated)
+# @parse url, title, img_src
from urllib import urlencode
from json import loads
+# engine dependent config
categories = ['images']
+paging = True
+# search-url
url = 'https://ajax.googleapis.com/'
search_url = url + 'ajax/services/search/images?v=1.0&start={offset}&rsz=large&safe=off&filter=off&{query}' # noqa
-paging = True
+# do search-request
def request(query, params):
offset = (params['pageno'] - 1) * 8
+
params['url'] = search_url.format(query=urlencode({'q': query}),
offset=offset)
+
return params
+# get response from search-request
def response(resp):
results = []
+
search_res = loads(resp.text)
- if not search_res.get('responseData'):
- return []
- if not search_res['responseData'].get('results'):
+
+ # return empty array if there are no results
+ if not search_res.get('responseData', {}).get('results'):
return []
+
+ # parse results
for result in search_res['responseData']['results']:
href = result['originalContextUrl']
title = result['title']
if not result['url']:
continue
+
+ # append result
results.append({'url': href,
'title': title,
'content': '',
'img_src': result['url'],
'template': 'images.html'})
+
+ # return results
return results