summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kukula <daniel.kuku@gmail.com>2024-05-03 16:52:02 +0100
committerBnyro <82752168+Bnyro@users.noreply.github.com>2024-05-03 21:37:37 +0200
commit46d7a8289bdf9aab1c1e170dc5257a78fc38f80a (patch)
treedc2b5606f196ba48b564efcb7961b7abeb68026e
parent04271e555b41138fcfcdd712323a62239e97e7c9 (diff)
downloadsearx-46d7a8289bdf9aab1c1e170dc5257a78fc38f80a.tar.gz
searx-46d7a8289bdf9aab1c1e170dc5257a78fc38f80a.zip
[feat] engine: implementation of https://hex.pm
The package manager for the Erlang ecosystem Find packages. Co-authored-by: Bnyro <82752168+Bnyro@users.noreply.github.com>
-rw-r--r--AUTHORS.rst1
-rw-r--r--searx/engines/hex.py56
-rw-r--r--searx/settings.yml5
3 files changed, 62 insertions, 0 deletions
diff --git a/AUTHORS.rst b/AUTHORS.rst
index a4478846a..011735b55 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -172,3 +172,4 @@ features or generally made searx better:
- Bernie Huang `<https://github.com/BernieHuang2008>`
- Austin Olacsi `<https://github.com/Austin-Olacsi>`
- @micsthepick
+- Daniel Kukula `<https://github.com/dkuku>`
diff --git a/searx/engines/hex.py b/searx/engines/hex.py
new file mode 100644
index 000000000..febd36d73
--- /dev/null
+++ b/searx/engines/hex.py
@@ -0,0 +1,56 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+"""hex.pm"""
+
+from urllib.parse import urlencode
+from dateutil import parser
+
+
+about = {
+ # pylint: disable=line-too-long
+ "website": "https://hex.pm/",
+ "wikidata_id": None,
+ "official_api_documentation": "https://github.com/hexpm/hexpm/blob/main/lib/hexpm_web/controllers/api/package_controller.ex",
+ "use_official_api": True,
+ "require_api_key": False,
+ "results": "JSON",
+}
+
+categories = ["it", "packages"]
+
+
+# engine dependent config
+paging = True
+search_url = "https://hex.pm/api/packages/"
+
+
+def request(query: str, params):
+ args = urlencode({"page": params["pageno"], "search": query})
+ params["url"] = f"{search_url}?{args}"
+ return params
+
+
+def response(resp):
+ results = []
+ for package in resp.json():
+ meta = package["meta"]
+ publishedDate = package.get("inserted_at")
+ if publishedDate:
+ publishedDate = parser.parse(publishedDate)
+ tags = meta.get("licenses", [])
+ results.append(
+ {
+ "template": "packages.html",
+ "url": package["url"],
+ "title": package["name"],
+ "package_name": package["name"],
+ "content": meta.get("description", ""),
+ "version": meta.get("latest_version"),
+ "maintainer": ", ".join(meta.get("maintainers", [])),
+ "publishedDate": publishedDate,
+ "tags": tags,
+ "homepage": meta.get("links", {}).get("homepage"),
+ "source_code_url": meta.get("links", {}).get("github"),
+ }
+ )
+
+ return results
diff --git a/searx/settings.yml b/searx/settings.yml
index a2b968832..a57bcfbd5 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -926,6 +926,11 @@ engines:
shortcut: hn
disabled: true
+ - name: hex
+ engine: hex
+ shortcut: hex
+ disabled: true
+
- name: hoogle
engine: xpath
search_url: https://hoogle.haskell.org/?hoogle={query}