mirror of
https://github.com/searxng/searxng.git
synced 2024-06-02 22:00:18 +02:00
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
# 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"]
|
|
published_date = package.get("updated_at")
|
|
published_date = parser.parse(published_date)
|
|
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": published_date,
|
|
"license_name": ", ".join(meta.get("licenses", [])),
|
|
"homepage": package["docs_html_url"],
|
|
"source_code_url": get_source_code_url(meta.get("links", {})),
|
|
}
|
|
)
|
|
|
|
return results
|
|
|
|
|
|
def get_source_code_url(links):
|
|
source_url = None
|
|
for k, v in links.items():
|
|
if not source_url and k.lower() in ["source", "github", "gitlab"]:
|
|
source_url = v
|
|
|
|
for k, v in links.items():
|
|
if not source_url and ("github" in v or "gitlab" in v):
|
|
source_url = v
|
|
|
|
return source_url
|