summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2024-01-05 18:03:07 +0100
committerAlexandre Flament <alex@al-f.net>2024-01-07 11:18:16 +0100
commit621e1313aff3c1fd7b6cc789d34311b11f877f43 (patch)
tree81f3a1226dfe3ee25f1b5caca772eb0ab68da535
parent2f7c800f6fd01d73f087d0c8bd85d657df32e49c (diff)
[feat] engine: implementation of stract (beta)
-rw-r--r--searx/engines/stract.py43
-rw-r--r--searx/settings.yml5
2 files changed, 48 insertions, 0 deletions
diff --git a/searx/engines/stract.py b/searx/engines/stract.py
new file mode 100644
index 00000000..c2497998
--- /dev/null
+++ b/searx/engines/stract.py
@@ -0,0 +1,43 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# lint: pylint
+"""Stract is an independent open source search engine.
+At this state, it's still in beta and hence this implementation will need to be updated once beta ends.
+"""
+
+from json import dumps
+
+about = {
+ "website": "https://stract.com/",
+ "use_official_api": True,
+ "official_api_documentation": "https://stract.com/beta/api/docs/#/search/api",
+ "require_api_key": False,
+ "results": "JSON",
+}
+categories = ['general']
+paging = True
+
+search_url = "https://stract.com/beta/api/search"
+
+
+def request(query, params):
+ params['url'] = search_url
+ params['method'] = "POST"
+ params['headers'] = {'Accept': 'application/json', 'Content-Type': 'application/json'}
+ params['data'] = dumps({'query': query, 'page': params['pageno'] - 1})
+
+ return params
+
+
+def response(resp):
+ results = []
+
+ for result in resp.json()["webpages"]:
+ results.append(
+ {
+ 'url': result['url'],
+ 'title': result['title'],
+ 'content': ''.join(fragment['text'] for fragment in result['snippet']['text']['fragments']),
+ }
+ )
+
+ return results
diff --git a/searx/settings.yml b/searx/settings.yml
index 5f1f7f22..61756187 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -2079,6 +2079,11 @@ engines:
timeout: 5.0
disabled: true
+ - name: stract
+ engine: stract
+ shortcut: str
+ disabled: true
+
- name: svgrepo
engine: svgrepo
shortcut: svg