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

Functions

 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ['social media']
 
str base_url = "https://mastodon.social"
 
str mastodon_type = "accounts"
 
int page_size = 40
 

Detailed Description

Mastodon_ is an open source alternative to large social media platforms like
Twitter/X, Facebook, ...

Since it's federated and self-hostable, there's a large amount of available
instances, which can be chosen instead by modifying ``base_url``.

We use their official API_ for searching, but unfortunately, their Search API_
forbids pagination without OAuth.

That's why we use tootfinder.ch for finding posts, which doesn't support searching
for users, accounts or other types of content on Mastodon however.

.. _Mastodon: https://mastodon.social
.. _API: https://docs.joinmastodon.org/api/

Function Documentation

◆ request()

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

Definition at line 39 of file mastodon.py.

39def request(query, params):
40 args = {
41 'q': query,
42 'resolve': 'false',
43 'type': mastodon_type,
44 'limit': page_size,
45 }
46 params['url'] = f"{base_url}/api/v2/search?{urlencode(args)}"
47 return params
48
49

◆ response()

searx.engines.mastodon.response ( resp)

Definition at line 50 of file mastodon.py.

50def response(resp):
51 results = []
52
53 json = resp.json()
54
55 for result in json[mastodon_type]:
56 if mastodon_type == "accounts":
57 results.append(
58 {
59 'url': result['uri'],
60 'title': result['username'] + f" ({result['followers_count']} followers)",
61 'content': result['note'],
62 'thumbnail': result.get('avatar'),
63 'publishedDate': datetime.strptime(result['created_at'][:10], "%Y-%m-%d"),
64 }
65 )
66 elif mastodon_type == "hashtags":
67 uses_count = sum(int(entry['uses']) for entry in result['history'])
68 user_count = sum(int(entry['accounts']) for entry in result['history'])
69 results.append(
70 {
71 'url': result['url'],
72 'title': result['name'],
73 'content': f"Hashtag has been used {uses_count} times by {user_count} different users",
74 }
75 )
76 else:
77 raise ValueError(f"Unsupported mastodon type: {mastodon_type}")
78
79 return results

Variable Documentation

◆ about

dict searx.engines.mastodon.about
Initial value:
1= {
2 "website": 'https://joinmastodon.org/',
3 "wikidata_id": 'Q27986619',
4 "official_api_documentation": 'https://docs.joinmastodon.org/api/',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 22 of file mastodon.py.

◆ base_url

str searx.engines.mastodon.base_url = "https://mastodon.social"

Definition at line 32 of file mastodon.py.

◆ categories

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

Definition at line 30 of file mastodon.py.

◆ mastodon_type

str searx.engines.mastodon.mastodon_type = "accounts"

Definition at line 33 of file mastodon.py.

◆ page_size

int searx.engines.mastodon.page_size = 40

Definition at line 36 of file mastodon.py.