publish-meetups/publish_meetups/feeds/mastodon_feed.py

39 lines
987 B
Python
Raw Permalink Normal View History

2024-02-11 18:00:48 +00:00
from pathlib import Path
from mastodon import Mastodon
from . import Feed
2024-02-13 20:43:29 +00:00
from ..utils import PROGRAM_DATA_DIR, prompt, config
2024-02-11 18:00:48 +00:00
class MastodonFeed(Feed):
2024-02-13 20:25:47 +00:00
__config_name__ = "mastodon"
2024-02-13 20:43:29 +00:00
CLIENTCRED_PATH: Path = PROGRAM_DATA_DIR.joinpath("mastodon_clientcred.secret")
2024-02-11 18:00:48 +00:00
2024-02-11 19:48:45 +00:00
@classmethod
2024-02-13 20:25:47 +00:00
def prompt_auth(cls) -> dict:
2024-02-11 18:00:48 +00:00
"""
mastodon needs:
- the instance used
2024-02-11 19:48:45 +00:00
- an access token
2024-02-11 18:00:48 +00:00
"""
return {
"api_base_url": prompt.for_string("The instance you use", "https://mastodon.social"),
2024-02-11 19:48:45 +00:00
"access_token": prompt.for_password("Access token"),
2024-02-11 18:00:48 +00:00
}
2024-02-11 19:48:45 +00:00
# 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,
)
2024-02-13 20:25:47 +00:00
super().__init__()
2024-02-11 19:48:45 +00:00
def post(self, message: str):
self.mastodon.toot(message)
2024-02-12 21:17:48 +00:00
2024-02-13 20:25:47 +00:00
super().post(message)