engine npm use the packages.html template

This commit is contained in:
Alexandre Flament 2024-03-01 10:36:40 +01:00 committed by Markus Heiser
parent 6dd07b88a4
commit 42515d98f7
2 changed files with 70 additions and 19 deletions

67
searx/engines/npm.py Normal file
View file

@ -0,0 +1,67 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
# lint: pylint
"""npms.io
"""
from urllib.parse import urlencode
from dateutil import parser
about = {
"website": "https://npms.io/",
"wikidata_id": "Q7067518",
"official_api_documentation": "https://api-docs.npms.io/",
"use_official_api": False,
"require_api_key": False,
"results": "JSON",
}
categories = ['it', 'packages']
# engine dependent config
paging = True
page_size = 25
search_api = "https://api.npms.io/v2/search?"
def request(query: str, params):
args = urlencode(
{
'from': (params["pageno"] - 1) * page_size,
'q': query,
'size': page_size,
}
)
params['url'] = search_api + args
return params
def response(resp):
results = []
content = resp.json()
for entry in content["results"]:
package = entry["package"]
publishedDate = package.get("date")
if publishedDate:
publishedDate = parser.parse(publishedDate)
tags = list(entry.get("flags", {}).keys()) + package.get("keywords", [])
results.append(
{
"template": "packages.html",
"url": package["links"]["npm"],
"title": package["name"],
'package_name': package["name"],
"content": package.get("description", ""),
"version": package.get("version"),
"maintainer": package.get("author", {}).get("name"),
'publishedDate': publishedDate,
"tags": tags,
"homepage": package["links"].get("homepage"),
"source_code_url": package["links"].get("repository"),
}
)
return results

View file

@ -1191,26 +1191,10 @@ engines:
disabled: true disabled: true
- name: npm - name: npm
engine: json_engine engine: npm
paging: true
first_page_num: 0
search_url: https://api.npms.io/v2/search?q={query}&size=25&from={pageno}
results_query: results
url_query: package/links/npm
title_query: package/name
content_query: package/description
page_size: 25
categories: [it, packages]
disabled: true
timeout: 5.0
shortcut: npm shortcut: npm
about: timeout: 5.0
website: https://npms.io/ disabled: true
wikidata_id: Q7067518
official_api_documentation: https://api-docs.npms.io/
use_official_api: false
require_api_key: false
results: JSON
- name: nyaa - name: nyaa
engine: nyaa engine: nyaa