summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2023-09-08 09:25:36 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2023-09-12 20:38:36 +0200
commit64d9587ac82564a80193e4891256652f709a91b9 (patch)
treeaef93a542daa06293b42c7e0eac8cbe04bc9e2ad /searx
parentaa1453db0c704b1222acb4761c86cd288f7a46f8 (diff)
downloadsearxng-64d9587ac82564a80193e4891256652f709a91b9.tar.gz
searxng-64d9587ac82564a80193e4891256652f709a91b9.zip
[feat] new engine: svgrepo
Diffstat (limited to 'searx')
-rw-r--r--searx/engines/svgrepo.py46
-rw-r--r--searx/settings.yml6
2 files changed, 52 insertions, 0 deletions
diff --git a/searx/engines/svgrepo.py b/searx/engines/svgrepo.py
new file mode 100644
index 000000000..19c37ff58
--- /dev/null
+++ b/searx/engines/svgrepo.py
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# lint: pylint
+"""Svgrepo (images)
+"""
+
+from lxml import html
+from searx.utils import extract_text, eval_xpath, eval_xpath_list
+
+about = {
+ "website": 'https://www.svgrepo.com',
+ "official_api_documentation": 'https://svgapi.com',
+ "use_official_api": False,
+ "require_api_key": False,
+ "results": 'HTML',
+}
+
+paging = True
+categories = ['images']
+base_url = "https://www.svgrepo.com"
+
+results_xpath = "//div[@class='style_nodeListing__7Nmro']/div"
+url_xpath = ".//a/@href"
+title_xpath = ".//a/@title"
+img_src_xpath = ".//img/@src"
+
+
+def request(query, params):
+ params['url'] = f"{base_url}/vectors/{query}/{params['pageno']}/"
+ return params
+
+
+def response(resp):
+ results = []
+
+ dom = html.fromstring(resp.text)
+ for result in eval_xpath_list(dom, results_xpath):
+ results.append(
+ {
+ 'template': 'images.html',
+ 'url': base_url + extract_text(eval_xpath(result, url_xpath)),
+ 'title': extract_text(eval_xpath(result, title_xpath)).replace(" SVG File", "").replace("Show ", ""),
+ 'img_src': extract_text(eval_xpath(result, img_src_xpath)),
+ }
+ )
+
+ return results
diff --git a/searx/settings.yml b/searx/settings.yml
index 72701ac48..9dfa03e0e 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -1869,6 +1869,12 @@ engines:
timeout: 5.0
disabled: true
+ - name: svgrepo
+ engine: svgrepo
+ shortcut: svg
+ timeout: 10.0
+ disabled: true
+
# wikimini: online encyclopedia for children
# The fulltext and title parameter is necessary for Wikimini because
# sometimes it will not show the results and redirect instead