.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
docker_hub.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Docker Hub (IT)
3
4"""
5# pylint: disable=use-dict-literal
6
7from urllib.parse import urlencode
8from dateutil import parser
9
10about = {
11 "website": 'https://hub.docker.com',
12 "wikidata_id": 'Q100769064',
13 "official_api_documentation": 'https://docs.docker.com/registry/spec/api/',
14 "use_official_api": True,
15 "require_api_key": False,
16 "results": 'JSON',
17}
18
19categories = ['it', 'packages'] # optional
20paging = True
21
22base_url = "https://hub.docker.com"
23page_size = 10
24
25
26def request(query, params):
27 args = {
28 "query": query,
29 "from": page_size * (params['pageno'] - 1),
30 "size": page_size,
31 }
32 params['url'] = f"{base_url}/api/search/v3/catalog/search?{urlencode(args)}"
33
34 return params
35
36
37def response(resp):
38 '''post-response callback
39 resp: requests response object
40 '''
41 results = []
42 json_resp = resp.json()
43
44 for item in json_resp.get("results", []):
45 image_source = item.get("source")
46 is_official = image_source in ["store", "official"]
47
48 popularity_infos = [f"{item.get('star_count', 0)} stars"]
49
50 architectures = []
51 for rate_plan in item.get("rate_plans", []):
52 pull_count = rate_plan.get("repositories", [{}])[0].get("pull_count")
53 if pull_count:
54 popularity_infos.insert(0, f"{pull_count} pulls")
55 architectures.extend(arch['name'] for arch in rate_plan.get("architectures", []) if arch['name'])
56
57 result = {
58 'template': 'packages.html',
59 'url': base_url + ("/_/" if is_official else "/r/") + item.get("slug", ""),
60 'title': item.get("name"),
61 'content': item.get("short_description"),
62 'thumbnail': item["logo_url"].get("large") or item["logo_url"].get("small"),
63 'package_name': item.get("name"),
64 'maintainer': item["publisher"].get("name"),
65 'publishedDate': parser.parse(item.get("updated_at") or item.get("created_at")),
66 'popularity': ', '.join(popularity_infos),
67 'tags': architectures,
68 }
69 results.append(result)
70
71 return results
request(query, params)
Definition docker_hub.py:26