geotribu_cli.social.mastodon_client module

class geotribu_cli.social.mastodon_client.ExtendedMastodonClient(client_id=None, client_secret=None, access_token=None, api_base_url='https://mapstodon.space/', debug_requests=None, ratelimit_method='wait', ratelimit_pacefactor=1.1, request_timeout=60, mastodon_version=None, version_check_mode='created', session=None, feature_set='mainline', user_agent='GeotribuToolbelt/0.33.0', lang='fra')

Bases : Mastodon

Extended Mastodon client with custom methods and attributes.

Lève:

MastodonError – if access token is not set

__init__(client_id=None, client_secret=None, access_token=None, api_base_url='https://mapstodon.space/', debug_requests=None, ratelimit_method='wait', ratelimit_pacefactor=1.1, request_timeout=60, mastodon_version=None, version_check_mode='created', session=None, feature_set='mainline', user_agent='GeotribuToolbelt/0.33.0', lang='fra')

Instanciation class. Args are inherited.

broadcast_comment(in_comment)

Post the latest comment to Mastodon.

Paramètres:

in_comment (Comment) – comment to broadcast

Type renvoyé:

dict

Renvoie:

URL to posted status

comment_already_broadcasted(comment_id)

Check if comment has already been broadcasted on the media.

Paramètres:

comment_id (int) – id of the comment to check

Type renvoyé:

Optional[dict]

Renvoie:

post on media if it has been already published

comment_to_media(in_comment)

Format comment to fit media size and publication rules.

Paramètres:

in_comment (Comment) – comment to format

Type renvoyé:

str

Renvoie:

formatted comment

csv_accounts_columns_names = ['Account address', 'Show boosts', 'Notify on new posts', 'Languages']
export_accounts(mastodon_accounts, dest_csv_path=PosixPath('/home/runner/.geotribu/mastodon/export/mastodon_comptes_suivis_geotribu.csv'), default_instance='mapstodon.space')

Export Mastodon following accounts into CSV file as web UI.

Paramètres:
  • mastodon_accounts (list[dict]) – list of accounts

  • dest_csv_path (Path) – path to the CSV file to write to. Defaults to default_dest_path_following_accounts.

  • default_instance (str) – default instance domain when account is on the same. Defaults to mapstodon.space.

Type renvoyé:

Path

Renvoie:

path to the CSV file

export_data(dest_path_following_accounts=PosixPath('/home/runner/.geotribu/mastodon/export/mastodon_comptes_suivis_geotribu.csv'), dest_path_lists=PosixPath('/home/runner/.geotribu/mastodon/export/mastodon_listes_geotribu.csv'), dest_path_lists_only_accounts=PosixPath('/home/runner/.geotribu/mastodon/export/mastodon_comptes_des_listes_geotribu'))

Export account data.

Paramètres:
  • dest_path_following_accounts (Optional[Path]) – path to the CSV file for following accounts export. Defaults to default_dest_path_following_accounts.

  • dest_path_lists (Optional[Path]) – path to the CSV file for lists export. Defaults to default_dest_path_lists.

  • dest_path_lists_only_accounts (Optional[Path]) – path to the CSV file for only accounts from lists export. Defaults to default_dest_path_lists_only_accounts.

Lève:

MastodonAPIError – when it’s impossible to perform API request for profile information.

Type renvoyé:

tuple[Optional[Path], Optional[Path], Optional[Path]]

Renvoie:

tuple of paths of exported files

export_lists(mastodon_lists, dest_csv_path=PosixPath('/home/runner/.geotribu/mastodon/export/mastodon_listes_geotribu.csv'), default_instance='mapstodon.space')

Export lists.

Paramètres:
  • mastodon_lists (dict[str, list[dict]]) – _description_

  • dest_csv_path (Path) – path to the CSV file to write to. Defaults to default_dest_path_following_accounts.

  • default_instance (str) – default instance domain when account is on the same. Defaults to mapstodon.space.

Type renvoyé:

Path

Renvoie:

path to the CSV file

classmethod full_account_with_instance(account, default_instance='mapstodon.space')

Make sure the account contains instance domain.

Paramètres:
  • default_instance (str) – default instance domain. Defaults to mapstodon.space.

  • account (dict) – account dictionary

Renvoie:

account with default instance if not present

Example:

>>> print(ExtendedMastodonClient.full_account_with_instance(account={"acct": "datagouvfr@social.numerique.gouv.fr"}))
datagouvfr@social.numerique.gouv.fr
>>> print(ExtendedMastodonClient.full_account_with_instance(account={"acct": "leaflet"}))
leaflet@mapstodon.space
>>> print(ExtendedMastodonClient.full_account_with_instance(account={"acct": "opengisch"}, default_instance="fosstodon.org))
opengisch@fosstodon.org
my_statuses: Optional[list] = None
classmethod url_to_instance_domain(url)

Extract instance domain from URL.

Paramètres:

url (str) – input URL

Type renvoyé:

str

Renvoie:

instance domain

Example:


>>> print(ExtendedMastodonClient.url_to_instance_domain(url="https://mapstodon.space/@geotribu"))
mapstodon.space