[feat] dockerhub: use packages template

This commit is contained in:
Bnyro 2024-02-19 20:22:54 +01:00 committed by Markus Heiser
parent 60d8414ef1
commit 1d6f475fbc
1 changed files with 18 additions and 21 deletions

View File

@ -5,7 +5,6 @@
""" """
# pylint: disable=use-dict-literal # pylint: disable=use-dict-literal
from json import loads
from urllib.parse import urlencode from urllib.parse import urlencode
from dateutil import parser from dateutil import parser
@ -18,7 +17,7 @@ about = {
"results": 'JSON', "results": 'JSON',
} }
categories = ['it'] # optional categories = ['it', 'packages'] # optional
paging = True paging = True
base_url = "https://hub.docker.com/" base_url = "https://hub.docker.com/"
@ -38,26 +37,24 @@ def response(resp):
resp: requests response object resp: requests response object
''' '''
results = [] results = []
body = loads(resp.text) body = resp.json()
# Make sure `summaries` isn't `null` for item in body.get("summaries", []):
search_res = body.get("summaries") filter_type = item.get("filter_type")
if search_res: is_official = filter_type in ["store", "official"]
for item in search_res:
result = {}
# Make sure correct URL is set result = {
filter_type = item.get("filter_type") 'template': 'packages.html',
is_official = filter_type in ["store", "official"] 'url': base_url + ("_/" if is_official else "r/") + item.get("slug", ""),
'title': item.get("name"),
if is_official: 'content': item.get("short_description"),
result["url"] = base_url + "_/" + item.get('slug', "") 'img_src': item["logo_url"].get("large") or item["logo_url"].get("small"),
else: 'package_name': item.get("name"),
result["url"] = base_url + "r/" + item.get('slug', "") 'maintainer': item["publisher"].get("name"),
result["title"] = item.get("name") 'publishedDate': parser.parse(item.get("updated_at") or item.get("created_at")),
result["content"] = item.get("short_description") 'popularity': item.get("pull_count", "0") + " pulls",
result["publishedDate"] = parser.parse(item.get("updated_at") or item.get("created_at")) 'tags': [arch['name'] for arch in item["architectures"]],
result["thumbnail"] = item["logo_url"].get("large") or item["logo_url"].get("small") }
results.append(result) results.append(result)
return results return results