Skip to content

Commit

Permalink
[fix] dockerhub: switch to new api path
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Heiser <markus.heiser@darmarit.de>
  • Loading branch information
Bnyro and return42 committed Dec 27, 2024
1 parent 73e395c commit d7eaca4
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions searx/engines/docker_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,40 @@ def request(query, params):
return params


base_url = "https://hub.docker.com"
page_size = 10


def request(query, params):
args = {
"query": query,
"from": page_size * (params['pageno'] - 1),
"size": page_size,
}
params['url'] = f"{base_url}/api/search/v3/catalog/search?{urlencode(args)}"

return params


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

for item in json_resp.get("results", []):
image_source = item.get("source")
is_official = image_source in ["store", "official"]

popularity_infos = [f"{item.get('star_count', 0)} stars"]

for item in body.get("summaries", []):
filter_type = item.get("filter_type")
is_official = filter_type in ["store", "official"]
architectures = []
for rate_plan in item.get("rate_plans", []):
pull_count = rate_plan.get("repositories", [{}])[0].get("pull_count")
if pull_count:
popularity_infos.insert(0, f"{pull_count} pulls")
architectures.extend(arch['name'] for arch in rate_plan.get("architectures", []) if arch['name'])

result = {
'template': 'packages.html',
Expand All @@ -51,8 +75,8 @@ def response(resp):
'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"]],
'popularity': ', '.join(popularity_infos),
'tags': architectures,
}
results.append(result)

Expand Down

0 comments on commit d7eaca4

Please sign in to comment.