mirror of
https://github.com/searxng/searxng.git
synced 2026-08-09 16:51:24 +00:00
Compare commits
4 Commits
0ac5254b8e
...
330d56bba9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
330d56bba9 | ||
|
|
36bcd6b551 | ||
|
|
8fabaf86b6 | ||
|
|
d501b0420a |
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,17 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
"""Yep (general, images, news)"""
|
"""Yep (general, images, news)"""
|
||||||
|
|
||||||
from datetime import datetime
|
import typing as t
|
||||||
|
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
|
from searx.result_types import EngineResults
|
||||||
from searx.utils import html_to_text
|
from searx.utils import html_to_text
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
from searx.extended_types import SXNG_Response
|
||||||
|
from searx.search.processors import OnlineParams
|
||||||
|
|
||||||
about = {
|
about = {
|
||||||
'website': 'https://yep.com/',
|
'website': 'https://yep.com/',
|
||||||
'official_api_documentation': 'https://docs.developer.yelp.com',
|
'official_api_documentation': 'https://docs.developer.yelp.com',
|
||||||
@@ -14,69 +21,32 @@ about = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
base_url = "https://api.yep.com"
|
base_url = "https://api.yep.com"
|
||||||
search_type = "web" # 'web', 'images', 'news'
|
|
||||||
|
|
||||||
safesearch = True
|
safesearch = True
|
||||||
safesearch_map = {0: 'off', 1: 'moderate', 2: 'strict'}
|
safesearch_map = {0: 'off', 1: 'moderate', 2: 'strict'}
|
||||||
|
|
||||||
enable_http2 = False
|
enable_http2 = False
|
||||||
|
|
||||||
|
results_per_page = 20
|
||||||
|
|
||||||
def request(query, params):
|
|
||||||
args = {
|
def request(query: str, params: 'OnlineParams') -> None:
|
||||||
'client': 'web',
|
args = {'query': query, 'safeSearch': safesearch_map[params['safesearch']], 'limit': results_per_page}
|
||||||
'no_correct': 'false',
|
|
||||||
'q': query,
|
|
||||||
'safeSearch': safesearch_map[params['safesearch']],
|
|
||||||
'type': search_type,
|
|
||||||
}
|
|
||||||
params['url'] = f"{base_url}/fs/2/search?{urlencode(args)}"
|
params['url'] = f"{base_url}/fs/2/search?{urlencode(args)}"
|
||||||
params['headers']['Referer'] = 'https://yep.com/'
|
params['headers']['Referer'] = 'https://yep.com/'
|
||||||
params['headers']['Origin'] = 'https://yep.com'
|
params['headers']['Origin'] = 'https://yep.com'
|
||||||
return params
|
|
||||||
|
|
||||||
|
|
||||||
def _web_result(result):
|
def response(resp: 'SXNG_Response') -> EngineResults:
|
||||||
return {
|
res = EngineResults()
|
||||||
'url': result['url'],
|
|
||||||
'title': result['title'],
|
|
||||||
'content': html_to_text(result['snippet']),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def _images_result(result):
|
|
||||||
return {
|
|
||||||
'template': 'images.html',
|
|
||||||
'url': result['host_page'],
|
|
||||||
'title': result.get('title', ''),
|
|
||||||
'content': '',
|
|
||||||
'img_src': result['image_id'],
|
|
||||||
'thumbnail_src': result['src'],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def _news_result(result):
|
|
||||||
return {
|
|
||||||
'url': result['url'],
|
|
||||||
'title': result['title'],
|
|
||||||
'content': html_to_text(result['snippet']),
|
|
||||||
'publishedDate': datetime.strptime(result['first_seen'][:19], '%Y-%m-%dT%H:%M:%S'),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def response(resp):
|
|
||||||
results = []
|
|
||||||
|
|
||||||
for result in resp.json()[1]['results']:
|
for result in resp.json()[1]['results']:
|
||||||
if search_type == "web":
|
res.add(
|
||||||
if result['type'] != 'Organic':
|
res.types.MainResult(
|
||||||
continue
|
url=result['url'],
|
||||||
results.append(_web_result(result))
|
title=result['title'],
|
||||||
elif search_type == "images":
|
content=html_to_text(result['snippet']),
|
||||||
results.append(_images_result(result))
|
)
|
||||||
elif search_type == "news":
|
)
|
||||||
results.append(_news_result(result))
|
|
||||||
else:
|
|
||||||
raise ValueError(f"Unsupported yep search type: {search_type}")
|
|
||||||
|
|
||||||
return results
|
return res
|
||||||
|
|||||||
@@ -688,22 +688,6 @@ engines:
|
|||||||
engine: yep
|
engine: yep
|
||||||
shortcut: yep
|
shortcut: yep
|
||||||
categories: general
|
categories: general
|
||||||
search_type: web
|
|
||||||
timeout: 15
|
|
||||||
disabled: true
|
|
||||||
|
|
||||||
- name: yep images
|
|
||||||
engine: yep
|
|
||||||
shortcut: yepi
|
|
||||||
categories: images
|
|
||||||
search_type: images
|
|
||||||
disabled: true
|
|
||||||
|
|
||||||
- name: yep news
|
|
||||||
engine: yep
|
|
||||||
shortcut: yepn
|
|
||||||
categories: news
|
|
||||||
search_type: news
|
|
||||||
disabled: true
|
disabled: true
|
||||||
|
|
||||||
- name: currency
|
- name: currency
|
||||||
|
|||||||
@@ -67,3 +67,13 @@
|
|||||||
class="checkbox-onoff"{{- ' ' -}}
|
class="checkbox-onoff"{{- ' ' -}}
|
||||||
{%- if checked -%} checked{%- endif -%}/>
|
{%- if checked -%} checked{%- endif -%}/>
|
||||||
{%- endmacro -%}
|
{%- endmacro -%}
|
||||||
|
|
||||||
|
<!-- iframe that additionally sets some extra feature attrs for videos -->
|
||||||
|
{%- macro iframe(iframe_src) -%}
|
||||||
|
<iframe data-src="{{iframe_src}}" frameborder="0" allowfullscreen
|
||||||
|
{% if result.parsed_url.hostname in ("www.youtube.com", ) -%}
|
||||||
|
allow="picture-in-picture" referrerpolicy="origin"
|
||||||
|
{%- endif -%}
|
||||||
|
>
|
||||||
|
</iframe>
|
||||||
|
{%- endmacro -%}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{% from 'simple/macros.html' import result_header, result_sub_header, result_sub_footer, result_footer with context %}
|
{% from 'simple/macros.html' import iframe, result_header, result_sub_header, result_sub_footer, result_footer with context %}
|
||||||
|
|
||||||
{{ result_header(result, favicons, image_proxify) -}}
|
{{ result_header(result, favicons, image_proxify) -}}
|
||||||
{{- result_sub_header(result) -}}
|
{{- result_sub_header(result) -}}
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
{{- result_sub_footer(result) -}}
|
{{- result_sub_footer(result) -}}
|
||||||
{% if result.iframe_src -%}
|
{% if result.iframe_src -%}
|
||||||
<div id="result-media-{{ index }}" class="embedded-content invisible">
|
<div id="result-media-{{ index }}" class="embedded-content invisible">
|
||||||
<iframe data-src="{{result.iframe_src}}" frameborder="0" allowfullscreen></iframe>
|
{{ iframe(result.iframe_src) }}
|
||||||
</div>
|
</div>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{% if result.audio_src -%}
|
{% if result.audio_src -%}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{% from 'simple/macros.html' import result_header, result_sub_header, result_sub_footer, result_footer with context %}
|
{% from 'simple/macros.html' import iframe, result_header, result_sub_header, result_sub_footer, result_footer with context %}
|
||||||
|
|
||||||
{{ result_header(result, favicons, image_proxify) }}
|
{{ result_header(result, favicons, image_proxify) }}
|
||||||
{{ result_sub_header(result) }}
|
{{ result_sub_header(result) }}
|
||||||
@@ -18,11 +18,7 @@
|
|||||||
{{- result_sub_footer(result) -}}
|
{{- result_sub_footer(result) -}}
|
||||||
{% if result.iframe_src -%}
|
{% if result.iframe_src -%}
|
||||||
<div id="result-video-{{ index }}" class="embedded-video invisible">
|
<div id="result-video-{{ index }}" class="embedded-video invisible">
|
||||||
<iframe data-src="{{result.iframe_src}}" frameborder="0" allowfullscreen
|
{{ iframe(result.iframe_src) }}
|
||||||
{% if result.parsed_url.hostname in ("www.youtube.com", ) -%}
|
|
||||||
allow="picture-in-picture" referrerpolicy="origin">
|
|
||||||
{%- endif -%}
|
|
||||||
</iframe>
|
|
||||||
</div>
|
</div>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{{ result_footer(result) }}
|
{{ result_footer(result) }}
|
||||||
|
|||||||
Reference in New Issue
Block a user