From d6a2d4f969369544cb4325a7870db00498878716 Mon Sep 17 00:00:00 2001 From: Kyle Anthony Williams Date: Sun, 7 Feb 2021 13:34:29 -0500 Subject: [PATCH] [enh] add engine - Docker Hub Slightly modified merge of commit [1cb1d3ac] from searx [PR 2543]: This adds Docker Hub .. as a search engine .. the engine's favicon was downloaded from the Docker Hub website with wget and converted to a PNG with ImageMagick .. It supports the parsing of URLs, titles, content, published dates, and thumbnails of Docker images. [1cb1d3ac] https://github.com/searx/searx/pull/2543/commits/1cb1d3ac [PR 2543] https://github.com/searx/searx/pull/2543 Signed-off-by: Markus Heiser --- searx/engines/docker_hub.py | 65 ++++++++++++++++++ searx/settings.yml | 5 ++ .../themes/oscar/img/icons/docker hub.png | Bin 0 -> 957 bytes 3 files changed, 70 insertions(+) create mode 100644 searx/engines/docker_hub.py create mode 100644 searx/static/themes/oscar/img/icons/docker hub.png diff --git a/searx/engines/docker_hub.py b/searx/engines/docker_hub.py new file mode 100644 index 000000000..d9d0f745b --- /dev/null +++ b/searx/engines/docker_hub.py @@ -0,0 +1,65 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# lint: pylint +# pylint: disable=missing-function-docstring +"""Docker Hub (IT) + +""" + +from json import loads +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'] # 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 = loads(resp.text) + + # Make sure `summaries` isn't `null` + search_res = body.get("summaries") + if search_res: + for item in search_res: + result = {} + + # Make sure correct URL is set + filter_type = item.get("filter_type") + is_official = filter_type in ["store", "official"] + + if is_official: + result["url"] = base_url + "_/" + item.get('slug', "") + else: + result["url"] = base_url + "r/" + item.get('slug', "") + result["title"] = item.get("name") + result["content"] = item.get("short_description") + result["publishedDate"] = parser.parse( + item.get("updated_at") or item.get("created_at") + ) + result["thumbnail"] = ( + item["logo_url"].get("large") or item["logo_url"].get("small") + ) + results.append(result) + + return results diff --git a/searx/settings.yml b/searx/settings.yml index c3d35ee2e..d3b7acc72 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -334,6 +334,11 @@ engines: engine : digg shortcut : dg + - name: docker hub + engine: docker_hub + shortcut: dh + categories: it + - name : erowid engine : xpath paging : True diff --git a/searx/static/themes/oscar/img/icons/docker hub.png b/searx/static/themes/oscar/img/icons/docker hub.png new file mode 100644 index 0000000000000000000000000000000000000000..ff4e84c9092df8afb052c861c2adb6be011c0328 GIT binary patch literal 957 zcmeAS@N?(olHy`uVBq!ia0vp^jv&mz3?z4IT9yMTmUKs7py0-S?mvmFK)ynLqiJ#!!Mvv!wUw6QUeBtR|yOZRx=nF#0%!^3bX-A*aY~5xc>kDU)4E`3$&6j7i?^E({&4vK~MVXMsm# zF#`j)5C}6~x?A@LD9B#o>Fdh=l!={#oqx~riOU!mn7ln*977@wuZ{3*YEj@x*&aAi z^8f!Ef*cYV0TO2$os+wiQgWSUIZ28;S}aZpSrKx%FEyx$#kKC+teTYPACqoH8+Gz2 z1u6Gha{ThV|1sj)kC$27KHKb?S)9C+>A^>pOn#!gN~hNe5684fHBx3_<~b|I7_-(_zJgN*+>MZ2HC z>@MB4cX!8sIr$yidNk$+&u+84&Q!EcRxQf9*lpIX>`d#HguQ%6=U#TN(mdelcW9e49zQb1P<_$lVt?#uK9?f2H z$6QY^=h*e13z=r8#T}2CII+SvT9MnRq?hx|hQ`Xh{M)a2=-*A|ZcDf*7y9pLY}yK` zcAWwX?js)RO^#ciocN`9jMeC>ZqpG~pDM2;p2kO99$qbnYwLd~?q54~qwm6B$Ca9x zSa$Pw-t#!w*!$xAo&ERf1t&%Smp&-QaZbJ_r$3mX{zG~&$9Fm5c_IhYgJWub2?W@+ z?(o=nayLW4zNQ;KKNp@>G+DRZ(0+-`QY(gnOTLy`Pfu10Rc88CemZkCiQ~bUs~R8I zPiM%E6EB?Ud9^*xaZ0LS_^!Pb)*#pJlE5 zAMni}OezBy5wG5+-aNeLg1hber*SXT<6mUX|9(~f%QyWq;`(PSp8TBS8aLyshh2VF zL7t4N?EAkJ&%WBsJA1eB#NnIr0l)s$|6tygRdO_s-vpEvRZCnWN>UO_QmvAUQh^kM zk%5t+u7Q!Rfq96bv6X?jm7%GwfvJ^&f&SO9L=+9V`6-!cmAEy;t$24AsDZ)L)z4*} HQ$iB}#0!M! literal 0 HcmV?d00001