
    i	                     P    d Z ddlmZ ddlmZ dddddd	d
ZdgZdZdZdZd Z	d Z
y)aR  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/

    )	urlencode)datetimezhttps://joinmastodon.org/	Q27986619z"https://docs.joinmastodon.org/api/TFJSON)websitewikidata_idofficial_api_documentationuse_official_apirequire_api_keyresultszsocial mediazhttps://mastodon.socialaccounts(   c                 R    | dt         t        d}t         dt        |       |d<   |S )Nfalse)qresolvetypelimitz/api/v2/search?url)mastodon_type	page_sizebase_urlr   )queryparamsargss      '/root/searxng/searx/engines/mastodon.pyrequestr   '   s5    	D  j	$/@AF5MM    c                    g }| j                         }|t           D ]  }t        dk(  rT|j                  |d   |d   d|d    dz   |d   |j                  d      t	        j
                  |d	   d d
 d      d       `t        dk(  rMt        d |d   D              }t        d |d   D              }|j                  |d   |d   d| d| dd       t        dt                |S )Nr   uriusernamez (followers_countz followers)noteavatar
created_at
   z%Y-%m-%d)r   titlecontent	thumbnailpublishedDatehashtagsc              3   8   K   | ]  }t        |d            yw)usesNint.0entrys     r   	<genexpr>zresponse.<locals>.<genexpr>C   s     OESv/O   historyc              3   8   K   | ]  }t        |d            yw)r   Nr.   r0   s     r   r3   zresponse.<locals>.<genexpr>D   s     SSz!23Sr4   r   namezHashtag has been used z
 times by z different users)r   r'   r(   zUnsupported mastodon type: )jsonr   appendgetr   strptimesum
ValueError)respr   r8   result
uses_count
user_counts         r   responserB   2   s   G99;D}% LJ&NN!%=#J/Bv>O7P6QQ\2]]%f~!'H!5%-%6%6vl7KCR7PR\%] j(OVI=NOOJS	ARSSJNN!%=#F^!7
|:j\Yij :=/JKK-L0 Nr   N)__doc__urllib.parser   r   about
categoriesr   r   r   r   rB    r   r   <module>rH      sR   " #  +"F	 
$ 	r   