summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
authorAdam Tauber <asciimoo@gmail.com>2016-12-28 20:00:53 +0100
committerGitHub <noreply@github.com>2016-12-28 20:00:53 +0100
commit8bff42f049dcac77559beaf2932a47921feb1d49 (patch)
tree00fd6b0b14773c0e20425d4a6478d67f244d64ed /searx/engines
parentf30d5e87938275219852c94d57771e182bfa435b (diff)
parentea034fafa994227ea89662710901e73cb901e28c (diff)
downloadsearxng-8bff42f049dcac77559beaf2932a47921feb1d49.tar.gz
searxng-8bff42f049dcac77559beaf2932a47921feb1d49.zip
Merge branch 'master' into languages
Diffstat (limited to 'searx/engines')
-rw-r--r--searx/engines/__init__.py15
-rw-r--r--searx/engines/google_news.py6
-rw-r--r--searx/engines/searx_engine.py57
3 files changed, 65 insertions, 13 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py
index cc200a0d1..5275351f1 100644
--- a/searx/engines/__init__.py
+++ b/searx/engines/__init__.py
@@ -34,7 +34,8 @@ engine_dir = dirname(realpath(__file__))
engines = {}
categories = {'general': []}
-_initialized = False
+
+languages = loads(open(engine_dir + '/../data/engines_languages.json').read())
engine_shortcuts = {}
engine_default_args = {'paging': False,
@@ -214,13 +215,7 @@ def get_engines_stats():
]
-if 'engines' not in settings or not settings['engines']:
- logger.error('No engines found. Edit your settings.yml')
- exit(2)
-
-languages = loads(open(engine_dir + '/../data/engines_languages.json').read())
-
-for engine_data in settings['engines']:
- engine = load_engine(engine_data)
- if engine is not None:
+def initialize_engines(engine_list):
+ for engine_data in engine_list:
+ engine = load_engine(engine_data)
engines[engine.name] = engine
diff --git a/searx/engines/google_news.py b/searx/engines/google_news.py
index ddacd1a61..49c6a5d50 100644
--- a/searx/engines/google_news.py
+++ b/searx/engines/google_news.py
@@ -72,9 +72,9 @@ def response(resp):
'content': ''.join(result.xpath('.//div[@class="st"]//text()')),
}
- img = result.xpath('.//img/@src')[0]
- if img and not img.startswith('data'):
- r['img_src'] = img
+ imgs = result.xpath('.//img/@src')
+ if len(imgs) and not imgs[0].startswith('data'):
+ r['img_src'] = imgs[0]
results.append(r)
diff --git a/searx/engines/searx_engine.py b/searx/engines/searx_engine.py
new file mode 100644
index 000000000..91c264498
--- /dev/null
+++ b/searx/engines/searx_engine.py
@@ -0,0 +1,57 @@
+"""
+ Searx (all)
+
+ @website https://github.com/asciimoo/searx
+ @provide-api yes (https://asciimoo.ithub.io/searx/dev/search_api.html)
+
+ @using-api yes
+ @results JSON
+ @stable yes (using api)
+ @parse url, title, content
+"""
+
+from json import loads
+from searx.engines import categories as searx_categories
+
+
+categories = searx_categories.keys()
+
+# search-url
+instance_urls = []
+instance_index = 0
+
+
+# do search-request
+def request(query, params):
+ global instance_index
+ params['url'] = instance_urls[instance_index % len(instance_urls)]
+ params['method'] = 'POST'
+
+ instance_index += 1
+
+ params['data'] = {
+ 'q': query,
+ 'pageno': params['pageno'],
+ 'language': params['language'],
+ 'time_range': params['time_range'],
+ 'category': params['category'],
+ 'format': 'json'
+ }
+
+ return params
+
+
+# get response from search-request
+def response(resp):
+
+ response_json = loads(resp.text)
+ results = response_json['results']
+
+ for i in ('answers', 'infoboxes'):
+ results.extend(response_json[i])
+
+ results.extend({'suggestion': s} for s in response_json['suggestions'])
+
+ results.append({'number_of_results': response_json['number_of_results']})
+
+ return results