.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
npm.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""npms.io
3
4"""
5
6from urllib.parse import urlencode
7from dateutil import parser
8
9
10about = {
11 "website": "https://npms.io/",
12 "wikidata_id": "Q7067518",
13 "official_api_documentation": "https://api-docs.npms.io/",
14 "use_official_api": False,
15 "require_api_key": False,
16 "results": "JSON",
17}
18
19categories = ['it', 'packages']
20
21
22# engine dependent config
23paging = True
24page_size = 25
25search_api = "https://api.npms.io/v2/search?"
26
27
28def request(query: str, params):
29
30 args = urlencode(
31 {
32 'from': (params["pageno"] - 1) * page_size,
33 'q': query,
34 'size': page_size,
35 }
36 )
37 params['url'] = search_api + args
38 return params
39
40
41def response(resp):
42 results = []
43 content = resp.json()
44 for entry in content["results"]:
45 package = entry["package"]
46 publishedDate = package.get("date")
47 if publishedDate:
48 publishedDate = parser.parse(publishedDate)
49 tags = list(entry.get("flags", {}).keys()) + package.get("keywords", [])
50 results.append(
51 {
52 "template": "packages.html",
53 "url": package["links"]["npm"],
54 "title": package["name"],
55 'package_name': package["name"],
56 "content": package.get("description", ""),
57 "version": package.get("version"),
58 "maintainer": package.get("author", {}).get("name"),
59 'publishedDate': publishedDate,
60 "tags": tags,
61 "homepage": package["links"].get("homepage"),
62 "source_code_url": package["links"].get("repository"),
63 }
64 )
65
66 return results
request(str query, params)
Definition npm.py:28
response(resp)
Definition npm.py:41