.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
pypi.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""pypi.org
3
4"""
5
6from urllib.parse import urlencode
7from dateutil import parser
8
9from lxml import html
10from searx.utils import (
11 eval_xpath_getindex,
12 eval_xpath_list,
13 extract_text,
14)
15
16# about
17about = {
18 "website": "https://pypi.org",
19 "wikidata_id": "Q2984686",
20 "official_api_documentation": "https://warehouse.readthedocs.io/api-reference/index.html",
21 "use_official_api": False,
22 "require_api_key": False,
23 "results": "HTML",
24}
25
26categories = ['it', 'packages']
27
28
29# engine dependent config
30first_page_num = 1
31base_url = "https://pypi.org"
32search_url = base_url + '/search/?{query}'
33
34
35def request(query, params):
36 args = {
37 "q": query,
38 "page": params['pageno'],
39 }
40 params['url'] = search_url.format(query=urlencode(args))
41 return params
42
43
44def response(resp):
45 results = []
46 dom = html.fromstring(resp.text)
47 for entry in eval_xpath_list(dom, '/html/body/main/div/div/div/form/div/ul/li/a[@class="package-snippet"]'):
48 url = base_url + extract_text(eval_xpath_getindex(entry, './@href', 0)) # type: ignore
49 title = extract_text(eval_xpath_getindex(entry, './h3/span[@class="package-snippet__name"]', 0))
50 version = extract_text(eval_xpath_getindex(entry, './h3/span[@class="package-snippet__version"]', 0))
51 created_at = extract_text(
52 eval_xpath_getindex(entry, './h3/span[@class="package-snippet__created"]/time/@datetime', 0)
53 )
54 content = extract_text(eval_xpath_getindex(entry, './p', 0))
55 results.append(
56 {
57 "template": "packages.html",
58 "url": url,
59 "title": title,
60 'package_name': title,
61 "content": content,
62 "version": version,
63 'publishedDate': parser.parse(created_at), # type: ignore
64 }
65 )
66
67 return results
request(query, params)
Definition pypi.py:35
response(resp)
Definition pypi.py:44