summaryrefslogtreecommitdiff
path: root/searx/engines/docker_hub.py
blob: 5963ee2c5c728a5a61b0c76d0a8f7c0665526099 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Docker Hub (IT)

"""
# pylint: disable=use-dict-literal

from urllib.parse import urlencode
from dateutil import parser

about = {
    "website": 'https://hub.docker.com',
    "wikidata_id": 'Q100769064',
    "official_api_documentation": 'https://docs.docker.com/registry/spec/api/',
    "use_official_api": True,
    "require_api_key": False,
    "results": 'JSON',
}

categories = ['it', 'packages']  # optional
paging = True

base_url = "https://hub.docker.com/"
search_url = base_url + "api/content/v1/products/search?{query}&type=image&page_size=25"


def request(query, params):

    params['url'] = search_url.format(query=urlencode(dict(q=query, page=params["pageno"])))
    params["headers"]["Search-Version"] = "v3"

    return params


def response(resp):
    '''post-response callback
    resp: requests response object
    '''
    results = []
    body = resp.json()

    for item in body.get("summaries", []):
        filter_type = item.get("filter_type")
        is_official = filter_type in ["store", "official"]

        result = {
            'template': 'packages.html',
            'url': base_url + ("_/" if is_official else "r/") + item.get("slug", ""),
            'title': item.get("name"),
            'content': item.get("short_description"),
            'thumbnail': item["logo_url"].get("large") or item["logo_url"].get("small"),
            'package_name': item.get("name"),
            'maintainer': item["publisher"].get("name"),
            'publishedDate': parser.parse(item.get("updated_at") or item.get("created_at")),
            'popularity': item.get("pull_count", "0") + " pulls",
            'tags': [arch['name'] for arch in item["architectures"]],
        }
        results.append(result)

    return results