.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
hex.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""hex.pm"""
3
4from urllib.parse import urlencode
5from dateutil import parser
6
7
8about = {
9 # pylint: disable=line-too-long
10 "website": "https://hex.pm/",
11 "wikidata_id": None,
12 "official_api_documentation": "https://github.com/hexpm/hexpm/blob/main/lib/hexpm_web/controllers/api/package_controller.ex",
13 "use_official_api": True,
14 "require_api_key": False,
15 "results": "JSON",
16}
17
18categories = ["it", "packages"]
19
20
21# engine dependent config
22paging = True
23search_url = "https://hex.pm/api/packages/"
24# Valid values: name inserted_at updated_at total_downloads recent_downloads
25sort_criteria = "recent_downloads"
26page_size = 10
27
28linked_terms = {
29 # lower-case : replacement
30 "author": "Author",
31 "bitbucket": "Bitbucket",
32 "bug tracker": "Issue tracker",
33 "changelog": "Changelog",
34 "doc": "Documentation",
35 "docs": "Documentation",
36 "documentation": "Documentation",
37 "github repository": "GitHub",
38 "github": "GitHub",
39 "gitlab": "GitLab",
40 "issues": "Issue tracker",
41 "project source code": "Source code",
42 "repository": "Source code",
43 "scm": "Source code",
44 "sourcehut": "SourceHut",
45 "sources": "Source code",
46 "sponsor": "Sponsors",
47 "sponsors": "Sponsors",
48 "website": "Homepage",
49}
50
51
52def request(query: str, params):
53 args = urlencode({"page": params["pageno"], "per_page": page_size, "sort": sort_criteria, "search": query})
54 params["url"] = f"{search_url}?{args}"
55 return params
56
57
58def response(resp):
59 results = []
60 for package in resp.json():
61 meta = package["meta"]
62 published_date = package.get("updated_at")
63 published_date = parser.parse(published_date)
64 links = {linked_terms.get(k.lower(), k): v for k, v in meta.get("links").items()}
65 results.append(
66 {
67 "template": "packages.html",
68 "url": package["html_url"],
69 "title": package["name"],
70 "package_name": package["name"],
71 "content": meta.get("description", ""),
72 "version": meta.get("latest_version"),
73 "maintainer": ", ".join(meta.get("maintainers", [])),
74 "publishedDate": published_date,
75 "license_name": ", ".join(meta.get("licenses", [])),
76 "homepage": package["docs_html_url"],
77 "links": links,
78 }
79 )
80
81 return results
request(str query, params)
Definition hex.py:52
response(resp)
Definition hex.py:58