diff options
author | Adam Tauber <asciimoo@gmail.com> | 2016-12-24 22:23:36 +0100 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2016-12-24 22:23:36 +0100 |
commit | b6fc1546160285a2e0049d20cbd7e64269db1875 (patch) | |
tree | 91b8497549c7590381ca9d7a3caa5a333013c41c /searx/engines/searx_engine.py | |
parent | 0171db5c3f6aca3e60af8b9e288dd6ea541e3e0c (diff) | |
download | searxng-b6fc1546160285a2e0049d20cbd7e64269db1875.tar.gz searxng-b6fc1546160285a2e0049d20cbd7e64269db1875.zip |
[enh] add searx engine
Diffstat (limited to 'searx/engines/searx_engine.py')
-rw-r--r-- | searx/engines/searx_engine.py | 57 |
1 files changed, 57 insertions, 0 deletions
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 |