reddit-mastodon-crossposter/masto.py
2022-12-09 00:04:01 +01:00

29 lines
658 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 = 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")
)
# test toot
mastodon.toot("Hello World")