.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
yep.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
"""Yep (general, images, news)
3
"""
4
5
from
datetime
import
datetime
6
from
urllib.parse
import
urlencode
7
from
searx.utils
import
html_to_text
8
9
about = {
10
'website'
:
'https://yep.com/'
,
11
'official_api_documentation'
:
'https://docs.developer.yelp.com'
,
12
'use_official_api'
:
False
,
13
'require_api_key'
:
False
,
14
'results'
:
'JSON'
,
15
}
16
17
base_url =
"https://api.yep.com"
18
search_type =
"web"
# 'web', 'images', 'news'
19
20
safesearch =
True
21
safesearch_map = {0:
'off'
, 1:
'moderate'
, 2:
'strict'
}
22
23
24
def
request
(query, params):
25
args = {
26
'client'
:
'web'
,
27
'no_correct'
:
'false'
,
28
'q'
: query,
29
'safeSearch'
: safesearch_map[params[
'safesearch'
]],
30
'type'
: search_type,
31
}
32
params[
'url'
] = f
"{base_url}/fs/2/search?{urlencode(args)}"
33
params[
'headers'
][
'Referer'
] =
'https://yep.com/'
34
return
params
35
36
37
def
_web_result
(result):
38
return
{
39
'url'
: result[
'url'
],
40
'title'
: result[
'title'
],
41
'content'
: html_to_text(result[
'snippet'
]),
42
}
43
44
45
def
_images_result
(result):
46
return
{
47
'template'
:
'images.html'
,
48
'url'
: result[
'host_page'
],
49
'title'
: result.get(
'title'
,
''
),
50
'content'
:
''
,
51
'img_src'
: result[
'image_id'
],
52
'thumbnail_src'
: result[
'src'
],
53
}
54
55
56
def
_news_result
(result):
57
return
{
58
'url'
: result[
'url'
],
59
'title'
: result[
'title'
],
60
'content'
: html_to_text(result[
'snippet'
]),
61
'publishedDate'
: datetime.strptime(result[
'first_seen'
][:19],
'%Y-%m-%dT%H:%M:%S'
),
62
}
63
64
65
def
response
(resp):
66
results = []
67
68
for
result
in
resp.json()[1][
'results'
]:
69
if
search_type ==
"web"
:
70
if
result[
'type'
] !=
'Organic'
:
71
continue
72
results.append(
_web_result
(result))
73
elif
search_type ==
"images"
:
74
results.append(
_images_result
(result))
75
elif
search_type ==
"news"
:
76
results.append(
_news_result
(result))
77
else
:
78
raise
ValueError(f
"Unsupported yep search type: {search_type}"
)
79
80
return
results
searx.engines.yep._web_result
_web_result(result)
Definition
yep.py:37
searx.engines.yep._images_result
_images_result(result)
Definition
yep.py:45
searx.engines.yep.request
request(query, params)
Definition
yep.py:24
searx.engines.yep._news_result
_news_result(result)
Definition
yep.py:56
searx.engines.yep.response
response(resp)
Definition
yep.py:65
searx.utils
Definition
utils.py:1
searxng
searx
engines
yep.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0