from pathlib import Path from mastodon import Mastodon from . import Feed from ..utils import Paths, PROGRAM_NAME, prompt class MastodonFeed(Feed): CLIENTCRED_PATH: Path = Paths.CONFIG_PATH.joinpath("mastodon_clientcred.secret") @classmethod def prompt_auth(cls, existing_config: dict) -> dict: """ mastodon needs: - the instance used - an access token """ return { **existing_config, "api_base_url": prompt.for_string("The instance you use", "https://mastodon.social"), "access_token": prompt.for_password("Access token"), } # https://github.com/halcy/Mastodon.py def __init__(self, api_base_url: str, access_token: str, **kwargs): self.mastodon = Mastodon( api_base_url=api_base_url, access_token=access_token, ) super().__init__(**kwargs) def post(self, message: str): kwargs = locals().copy() self.mastodon.toot(message) Feed.post(**kwargs)