.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
seekr.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""seekr.com Seeker Score
3
4Seekr is a privately held search and content evaluation engine that prioritizes
5credibility over popularity.
6
7Configuration
8=============
9
10The engine has the following additional settings:
11
12- :py:obj:`seekr_category`
13- :py:obj:`api_key`
14
15This implementation is used by seekr engines in the :ref:`settings.yml
16<settings engine>`:
17
18.. code:: yaml
19
20 - name: seekr news
21 seekr_category: news
22 ...
23 - name: seekr images
24 seekr_category: images
25 ...
26 - name: seekr videos
27 seekr_category: videos
28 ...
29
30Known Quirks
31============
32
33The implementation to support :py:obj:`paging <searx.enginelib.Engine.paging>`
34is based on the *nextpage* method of Seekr's REST API. This feature is *next
35page driven* and plays well with the :ref:`infinite_scroll <settings ui>`
36setting in SearXNG but it does not really fit into SearXNG's UI to select a page
37by number.
38
39Implementations
40===============
41
42"""
43
44from datetime import datetime
45from json import loads
46from urllib.parse import urlencode
47from flask_babel import gettext
48
49about = {
50 "website": 'https://seekr.com/',
51 "official_api_documentation": None,
52 "use_official_api": False,
53 "require_api_key": True,
54 "results": 'JSON',
55 "language": 'en',
56}
57
58base_url = "https://api.seekr.com"
59paging = True
60
61api_key = "srh1-22fb-sekr"
62"""API key / reversed engineered / is still the same one since 2022."""
63
64seekr_category: str = 'unset'
65"""Search category, any of ``news``, ``videos`` or ``images``."""
66
67
68def init(engine_settings):
69
70 # global paging
71 if engine_settings['seekr_category'] not in ['news', 'videos', 'images']:
72 raise ValueError(f"Unsupported seekr category: {engine_settings['seekr_category']}")
73
74
75def request(query, params):
76
77 if not query:
78 return None
79
80 args = {
81 'query': query,
82 'apiKey': api_key,
83 }
84
85 api_url = base_url + '/engine'
86 if seekr_category == 'news':
87 api_url += '/v2/newssearch'
88
89 elif seekr_category == 'images':
90 api_url += '/imagetab'
91
92 elif seekr_category == 'videos':
93 api_url += '/videotab'
94
95 params['url'] = f"{api_url}?{urlencode(args)}"
96 if params['pageno'] > 1:
97 nextpage = params['engine_data'].get('nextpage')
98 if nextpage:
99 params['url'] = nextpage
100
101 return params
102
103
105
106 search_results = json.get('expertResponses')
107 if search_results:
108 search_results = search_results[0].get('advice')
109 else: # response from a 'nextResultSet'
110 search_results = json.get('advice')
111
112 results = []
113 if not search_results:
114 return results
115
116 for result in search_results['results']:
117 summary = loads(result['summary'])
118 results.append(
119 {
120 'template': 'images.html',
121 'url': summary['refererurl'],
122 'title': result['title'],
123 'img_src': result['url'],
124 'resolution': f"{summary['width']}x{summary['height']}",
125 'thumbnail_src': 'https://media.seekr.com/engine/rp/' + summary['tg'] + '/?src= ' + result['thumbnail'],
126 }
127 )
128
129 if search_results.get('nextResultSet'):
130 results.append(
131 {
132 "engine_data": search_results.get('nextResultSet'),
133 "key": "nextpage",
134 }
135 )
136 return results
137
138
140
141 search_results = json.get('expertResponses')
142 if search_results:
143 search_results = search_results[0].get('advice')
144 else: # response from a 'nextResultSet'
145 search_results = json.get('advice')
146
147 results = []
148 if not search_results:
149 return results
150
151 for result in search_results['results']:
152 summary = loads(result['summary'])
153 results.append(
154 {
155 'template': 'videos.html',
156 'url': result['url'],
157 'title': result['title'],
158 'thumbnail': 'https://media.seekr.com/engine/rp/' + summary['tg'] + '/?src= ' + result['thumbnail'],
159 }
160 )
161
162 if search_results.get('nextResultSet'):
163 results.append(
164 {
165 "engine_data": search_results.get('nextResultSet'),
166 "key": "nextpage",
167 }
168 )
169 return results
170
171
173
174 search_results = json.get('expertResponses')
175 if search_results:
176 search_results = search_results[0]['advice']['categorySearchResult']['searchResult']
177 else: # response from a 'nextResultSet'
178 search_results = json.get('advice')
179
180 results = []
181 if not search_results:
182 return results
183
184 for result in search_results['results']:
185
186 results.append(
187 {
188 'url': result['url'],
189 'title': result['title'],
190 'content': result['summary'] or result["topCategory"] or result["displayUrl"] or '',
191 'thumbnail': result.get('thumbnail', ''),
192 'publishedDate': datetime.strptime(result['pubDate'][:19], '%Y-%m-%d %H:%M:%S'),
193 'metadata': gettext("Language") + ': ' + result.get('language', ''),
194 }
195 )
196
197 if search_results.get('nextResultSet'):
198 results.append(
199 {
200 "engine_data": search_results.get('nextResultSet'),
201 "key": "nextpage",
202 }
203 )
204 return results
205
206
207def response(resp):
208 json = resp.json()
209
210 if seekr_category == "videos":
211 return _videos_response(json)
212 if seekr_category == "images":
213 return _images_response(json)
214 if seekr_category == "news":
215 return _news_response(json)
216
217 raise ValueError(f"Unsupported seekr category: {seekr_category}")
_news_response(json)
Definition seekr.py:172
request(query, params)
Definition seekr.py:75
init(engine_settings)
Definition seekr.py:68
_videos_response(json)
Definition seekr.py:139
_images_response(json)
Definition seekr.py:104