mirror of
https://github.com/searxng/searxng.git
synced 2026-09-23 14:46:04 +00:00
[feat] engines: add iconify - icons (#6541)
This commit is contained in:
50
searx/engines/iconify.py
Normal file
50
searx/engines/iconify.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""Iconify aggregates icons from different open source icon sets."""
|
||||
|
||||
import typing as t
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from searx.result_types import EngineResults
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from extended_types import SXNG_Response
|
||||
from search.processors.online import OnlineParams
|
||||
|
||||
|
||||
about = {
|
||||
"website": "https://iconify.design",
|
||||
"wikidata_id": None,
|
||||
"official_api_documentation": "https://iconify.design/docs/api/queries.html",
|
||||
"use_official_api": True,
|
||||
"results": "JSON",
|
||||
}
|
||||
|
||||
categories = ["images", "icons"]
|
||||
paging = True
|
||||
|
||||
base_url = "https://api.iconify.design"
|
||||
page_size = 20
|
||||
|
||||
|
||||
def request(query: str, params: "OnlineParams"):
|
||||
# actual number of results isn't exaxctly the same as the page size, only approximately
|
||||
args = {"query": query, "start": (params["pageno"] - 1) * page_size, "limit": page_size}
|
||||
params["url"] = f"{base_url}/search?{urlencode(args)}"
|
||||
|
||||
|
||||
def response(resp: "SXNG_Response") -> EngineResults:
|
||||
res = EngineResults()
|
||||
|
||||
for icon in resp.json()["icons"]:
|
||||
icon: str
|
||||
icon_source, icon_name = icon.split(":", 1)
|
||||
icon_url = f"{base_url}/{icon_source}/{icon_name}.svg"
|
||||
res.add(
|
||||
res.types.Image(
|
||||
url=icon_url,
|
||||
title=icon_name,
|
||||
img_src=icon_url,
|
||||
)
|
||||
)
|
||||
|
||||
return res
|
||||
@@ -1321,6 +1321,11 @@ engines:
|
||||
require_api_key: false
|
||||
results: JSON
|
||||
|
||||
- name: iconify
|
||||
engine: iconify
|
||||
shortcut: ico
|
||||
disabled: true
|
||||
|
||||
- name: iseek
|
||||
engine: iseek
|
||||
shortcut: isk
|
||||
|
||||
Reference in New Issue
Block a user