From 42515d98f72ad563aea79e69c17a837cc391f4c6 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Fri, 1 Mar 2024 10:36:40 +0100 Subject: [PATCH] engine npm use the packages.html template --- searx/engines/npm.py | 67 ++++++++++++++++++++++++++++++++++++++++++++ searx/settings.yml | 22 ++------------- 2 files changed, 70 insertions(+), 19 deletions(-) create mode 100644 searx/engines/npm.py diff --git a/searx/engines/npm.py b/searx/engines/npm.py new file mode 100644 index 000000000..0fef2dda8 --- /dev/null +++ b/searx/engines/npm.py @@ -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 diff --git a/searx/settings.yml b/searx/settings.yml index 3f817edb7..c3e0e514a 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -1191,26 +1191,10 @@ engines: disabled: true - name: npm - engine: json_engine - 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 + engine: npm shortcut: npm - 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 + timeout: 5.0 + disabled: true - name: nyaa engine: nyaa