.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
5from datetime import datetime
6from urllib.parse import urlencode
7from searx.utils import html_to_text
8
9about = {
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
17base_url = "https://api.yep.com"
18search_type = "web" # 'web', 'images', 'news'
19
20safesearch = True
21safesearch_map = {0: 'off', 1: 'moderate', 2: 'strict'}
22
23
24def 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
37def _web_result(result):
38 return {
39 'url': result['url'],
40 'title': result['title'],
41 'content': html_to_text(result['snippet']),
42 }
43
44
45def _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
56def _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
65def 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
_web_result(result)
Definition yep.py:37
_images_result(result)
Definition yep.py:45
request(query, params)
Definition yep.py:24
_news_result(result)
Definition yep.py:56
response(resp)
Definition yep.py:65