.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.lemmy Namespace Reference

Functions

 request (query, params)
 
 _get_communities (json)
 
 _get_users (json)
 
 _get_posts (json)
 
 _get_comments (json)
 
 response (resp)
 

Variables

dict about
 
bool paging = True
 
list categories = ['social media']
 
str base_url = "https://lemmy.ml/"
 
str lemmy_type = "Communities"
 

Detailed Description

This engine uses the Lemmy API (https://lemmy.ml/api/v3/search), which is
documented at `lemmy-js-client`_ / `Interface Search`_.  Since Lemmy is
federated, results are from many different, independent lemmy instances, and not
only the official one.

.. _lemmy-js-client: https://join-lemmy.org/api/modules.html
.. _Interface Search: https://join-lemmy.org/api/interfaces/Search.html

Configuration
=============

The engine has the following additional settings:

- :py:obj:`base_url`
- :py:obj:`lemmy_type`

This implementation is used by different lemmy engines in the :ref:`settings.yml
<settings engine>`:

.. code:: yaml

  - name: lemmy communities
    lemmy_type: Communities
    ...
  - name: lemmy users
    lemmy_type: Users
    ...
  - name: lemmy posts
    lemmy_type: Posts
    ...
  - name: lemmy comments
    lemmy_type: Comments
    ...

Implementations
===============

Function Documentation

◆ _get_comments()

searx.engines.lemmy._get_comments ( json)
protected

Definition at line 152 of file lemmy.py.

152def _get_comments(json):
153 results = []
154
155 for result in json["comments"]:
156 user = result['creator'].get('display_name', result['creator']['name'])
157
158 content = result['comment'].get('content', '').strip()
159 if content:
160 content = markdown_to_text(content)
161
162 metadata = (
163 f"&#x25B2; {result['counts']['upvotes']} &#x25BC; {result['counts']['downvotes']}"
164 f" | {gettext('user')}: {user}"
165 f" | {gettext('community')}: {result['community']['title']}"
166 )
167
168 results.append(
169 {
170 'url': result['comment']['ap_id'],
171 'title': result['post']['name'],
172 'content': markdown_to_text(result['comment']['content']),
173 'publishedDate': datetime.strptime(result['comment']['published'][:19], '%Y-%m-%dT%H:%M:%S'),
174 'metadata': metadata,
175 }
176 )
177
178 return results
179
180

Referenced by searx.engines.lemmy.response().

+ Here is the caller graph for this function:

◆ _get_communities()

searx.engines.lemmy._get_communities ( json)
protected

Definition at line 79 of file lemmy.py.

79def _get_communities(json):
80 results = []
81
82 for result in json["communities"]:
83 counts = result['counts']
84 metadata = (
85 f"{gettext('subscribers')}: {counts.get('subscribers', 0)}"
86 f" | {gettext('posts')}: {counts.get('posts', 0)}"
87 f" | {gettext('active users')}: {counts.get('users_active_half_year', 0)}"
88 )
89 results.append(
90 {
91 'url': result['community']['actor_id'],
92 'title': result['community']['title'],
93 'content': markdown_to_text(result['community'].get('description', '')),
94 'thumbnail': result['community'].get('icon', result['community'].get('banner')),
95 'publishedDate': datetime.strptime(counts['published'][:19], '%Y-%m-%dT%H:%M:%S'),
96 'metadata': metadata,
97 }
98 )
99 return results
100
101

Referenced by searx.engines.lemmy.response().

+ Here is the caller graph for this function:

◆ _get_posts()

searx.engines.lemmy._get_posts ( json)
protected

Definition at line 117 of file lemmy.py.

117def _get_posts(json):
118 results = []
119
120 for result in json["posts"]:
121 user = result['creator'].get('display_name', result['creator']['name'])
122
123 thumbnail = None
124 if result['post'].get('thumbnail_url'):
125 thumbnail = result['post']['thumbnail_url'] + '?format=webp&thumbnail=208'
126
127 metadata = (
128 f"&#x25B2; {result['counts']['upvotes']} &#x25BC; {result['counts']['downvotes']}"
129 f" | {gettext('user')}: {user}"
130 f" | {gettext('comments')}: {result['counts']['comments']}"
131 f" | {gettext('community')}: {result['community']['title']}"
132 )
133
134 content = result['post'].get('body', '').strip()
135 if content:
136 content = markdown_to_text(content)
137
138 results.append(
139 {
140 'url': result['post']['ap_id'],
141 'title': result['post']['name'],
142 'content': content,
143 'thumbnail': thumbnail,
144 'publishedDate': datetime.strptime(result['post']['published'][:19], '%Y-%m-%dT%H:%M:%S'),
145 'metadata': metadata,
146 }
147 )
148
149 return results
150
151

Referenced by searx.engines.lemmy.response().

+ Here is the caller graph for this function:

◆ _get_users()

searx.engines.lemmy._get_users ( json)
protected

Definition at line 102 of file lemmy.py.

102def _get_users(json):
103 results = []
104
105 for result in json["users"]:
106 results.append(
107 {
108 'url': result['person']['actor_id'],
109 'title': result['person']['name'],
110 'content': markdown_to_text(result['person'].get('bio', '')),
111 }
112 )
113
114 return results
115
116

Referenced by searx.engines.lemmy.response().

+ Here is the caller graph for this function:

◆ request()

searx.engines.lemmy.request ( query,
params )

Definition at line 68 of file lemmy.py.

68def request(query, params):
69 args = {
70 'q': query,
71 'page': params['pageno'],
72 'type_': lemmy_type,
73 }
74
75 params['url'] = f"{base_url}api/v3/search?{urlencode(args)}"
76 return params
77
78

◆ response()

searx.engines.lemmy.response ( resp)

Definition at line 181 of file lemmy.py.

181def response(resp):
182 json = resp.json()
183
184 if lemmy_type == "Communities":
185 return _get_communities(json)
186
187 if lemmy_type == "Users":
188 return _get_users(json)
189
190 if lemmy_type == "Posts":
191 return _get_posts(json)
192
193 if lemmy_type == "Comments":
194 return _get_comments(json)
195
196 raise ValueError(f"Unsupported lemmy type: {lemmy_type}")

References searx.engines.lemmy._get_comments(), searx.engines.lemmy._get_communities(), searx.engines.lemmy._get_posts(), and searx.engines.lemmy._get_users().

+ Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.lemmy.about
Initial value:
1= {
2 "website": 'https://lemmy.ml/',
3 "wikidata_id": 'Q84777032',
4 "official_api_documentation": "https://join-lemmy.org/api/",
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 48 of file lemmy.py.

◆ base_url

str searx.engines.lemmy.base_url = "https://lemmy.ml/"

Definition at line 59 of file lemmy.py.

◆ categories

list searx.engines.lemmy.categories = ['social media']

Definition at line 57 of file lemmy.py.

◆ lemmy_type

str searx.engines.lemmy.lemmy_type = "Communities"

Definition at line 64 of file lemmy.py.

◆ paging

bool searx.engines.lemmy.paging = True

Definition at line 56 of file lemmy.py.