reddit-mastodon-crossposter/masto.py
2023-08-01 18:59:46 +02:00

33 lines
740 B
Python

"""Initialize Mastodon.py, login the account and register an application"""
from dotenv import load_dotenv
from mastodon import Mastodon
from os import getenv
# ----- load .env ----- #
load_dotenv()
# ----- register application ----- #
Mastodon.create_app(
getenv("MASTODON_APP_NAME"),
api_base_url = str(getenv("MASTODON_URL")),
to_file = getenv("MASTODON_CLIENT_SECRET")
)
# ----- login Mastodon account ----- #
mastodon = Mastodon(
client_id = getenv("MASTODON_CLIENT_SECRET"),
api_base_url = getenv("MASTODON_URL")
)
mastodon.log_in(
getenv("MASTODON_USERNAME"),
getenv("MASTODON_PASSWORD"),
to_file = getenv("MASTODON_USER_SECRET")
)
# ----- post test toot ----- #
mastodon.toot("Hello World")