2023-10-16 10:45:09 +02:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2025-09-26 12:35:57 +02:00
|
|
|
"""Yep (general, images, news)"""
|
2023-10-16 10:45:09 +02:00
|
|
|
|
2026-05-06 08:17:19 +02:00
|
|
|
import typing as t
|
|
|
|
|
|
2023-10-16 10:45:09 +02:00
|
|
|
from urllib.parse import urlencode
|
2026-05-06 08:17:19 +02:00
|
|
|
|
|
|
|
|
from searx.result_types import EngineResults
|
2023-10-16 10:45:09 +02:00
|
|
|
from searx.utils import html_to_text
|
|
|
|
|
|
2026-05-06 08:17:19 +02:00
|
|
|
if t.TYPE_CHECKING:
|
|
|
|
|
from searx.extended_types import SXNG_Response
|
|
|
|
|
from searx.search.processors import OnlineParams
|
|
|
|
|
|
2023-10-16 10:45:09 +02:00
|
|
|
about = {
|
|
|
|
|
'website': 'https://yep.com/',
|
|
|
|
|
'official_api_documentation': 'https://docs.developer.yelp.com',
|
|
|
|
|
'use_official_api': False,
|
|
|
|
|
'require_api_key': False,
|
|
|
|
|
'results': 'JSON',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base_url = "https://api.yep.com"
|
|
|
|
|
|
|
|
|
|
safesearch = True
|
|
|
|
|
safesearch_map = {0: 'off', 1: 'moderate', 2: 'strict'}
|
|
|
|
|
|
2025-12-29 16:27:15 +01:00
|
|
|
enable_http2 = False
|
|
|
|
|
|
2026-05-06 08:17:19 +02:00
|
|
|
results_per_page = 20
|
2023-10-16 10:45:09 +02:00
|
|
|
|
2026-05-06 08:17:19 +02:00
|
|
|
|
|
|
|
|
def request(query: str, params: 'OnlineParams') -> None:
|
|
|
|
|
args = {'query': query, 'safeSearch': safesearch_map[params['safesearch']], 'limit': results_per_page}
|
2023-10-16 10:45:09 +02:00
|
|
|
params['url'] = f"{base_url}/fs/2/search?{urlencode(args)}"
|
|
|
|
|
params['headers']['Referer'] = 'https://yep.com/'
|
2025-12-29 16:27:15 +01:00
|
|
|
params['headers']['Origin'] = 'https://yep.com'
|
2023-10-16 10:45:09 +02:00
|
|
|
|
|
|
|
|
|
2026-05-06 08:17:19 +02:00
|
|
|
def response(resp: 'SXNG_Response') -> EngineResults:
|
|
|
|
|
res = EngineResults()
|
2023-10-16 10:45:09 +02:00
|
|
|
|
|
|
|
|
for result in resp.json()[1]['results']:
|
2026-05-06 08:17:19 +02:00
|
|
|
res.add(
|
|
|
|
|
res.types.MainResult(
|
|
|
|
|
url=result['url'],
|
|
|
|
|
title=result['title'],
|
|
|
|
|
content=html_to_text(result['snippet']),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return res
|