.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
crates.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
"""Cargo search on crates.io"""
3
4
from
collections
import
OrderedDict
5
from
urllib.parse
import
urlencode
6
7
from
dateutil
import
parser
8
9
about = {
10
"website"
:
"https://crates.io/"
,
11
"wikidata_id"
:
None
,
12
"official_api_documentation"
:
"https://crates.io/data-access"
,
13
"use_official_api"
:
True
,
14
"require_api_key"
:
False
,
15
"results"
:
"JSON"
,
16
}
17
18
categories = [
"it"
,
"packages"
,
"cargo"
]
19
20
21
# engine dependent config
22
paging =
True
23
page_size = 10
24
search_url =
"https://crates.io/api/v1/crates"
25
26
linked_terms = OrderedDict(
27
[
28
(
"homepage"
,
"Project homepage"
),
29
(
"documentation"
,
"Documentation"
),
30
(
"repository"
,
"Source code"
),
31
]
32
)
33
34
35
def
request
(query: str, params):
36
37
args = urlencode({
"page"
: params[
"pageno"
],
"q"
: query,
"per_page"
: page_size})
38
params[
"url"
] = f
"{search_url}?{args}"
39
return
params
40
41
42
def
response
(resp):
43
results = []
44
45
for
package
in
resp.json()[
"crates"
]:
46
47
published_date = package.get(
"updated_at"
)
48
published_date = parser.parse(published_date)
49
50
links = {}
51
for
k, v
in
linked_terms.items():
52
l = package.get(k)
53
if
l:
54
links[v] = l
55
56
results.append(
57
{
58
"template"
:
"packages.html"
,
59
"url"
: f
'https://crates.io/crates/{package["name"]}'
,
60
"title"
: package[
"name"
],
61
"package_name"
: package[
"name"
],
62
"tags"
: package[
"keywords"
],
63
"content"
: package[
"description"
],
64
"version"
: package[
"newest_version"
]
or
package[
"max_version"
]
or
package[
"max_stable_version"
],
65
"publishedDate"
: published_date,
66
"links"
: links,
67
}
68
)
69
70
return
results
searx.engines.crates.request
request(str query, params)
Definition
crates.py:35
searx.engines.crates.response
response(resp)
Definition
crates.py:42
searxng
searx
engines
crates.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0