.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
mrs.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Matrix Rooms Search - a fully-featured, standalone, matrix rooms search service.
3
4Configuration
5=============
6
7The engine has the following mandatory settings:
8
9- :py:obj:`base_url`
10
11.. code:: yaml
12
13 - name: MRS
14 engine: mrs
15 base_url: https://mrs-host
16 ...
17
18Implementation
19==============
20"""
21
22from urllib.parse import quote_plus
23
24about = {
25 "website": 'https://matrixrooms.info',
26 "wikidata_id": None,
27 "official_api_documentation": 'https://gitlab.com/etke.cc/mrs/api/-/blob/main/openapi.yml?ref_type=heads',
28 "use_official_api": True,
29 "require_api_key": False,
30 "results": 'JSON',
31}
32paging = True
33categories = ['social media']
34
35base_url = ""
36matrix_url = "https://matrix.to"
37page_size = 20
38
39
40def init(engine_settings): # pylint: disable=unused-argument
41 """The ``base_url`` must be set in the configuration, if ``base_url`` is not
42 set, a :py:obj:`ValueError` is raised during initialization.
43
44 """
45 if not base_url:
46 raise ValueError('engine MRS, base_url is unset')
47
48
49def request(query, params):
50 params['url'] = f"{base_url}/search/{quote_plus(query)}/{page_size}/{(params['pageno']-1)*page_size}"
51 return params
52
53
54def response(resp):
55 results = []
56
57 for result in resp.json():
58 results.append(
59 {
60 'url': matrix_url + '/#/' + result['alias'],
61 'title': result['name'],
62 'content': result['topic']
63 + f" // {result['members']} members"
64 + f" // {result['alias']}"
65 + f" // {result['server']}",
66 'thumbnail': result['avatar_url'],
67 }
68 )
69
70 return results
response(resp)
Definition mrs.py:54
init(engine_settings)
Definition mrs.py:40
request(query, params)
Definition mrs.py:49