2022-12-09 00:04:01 +01:00
|
|
|
"""Initialize Mastodon.py, login the account and register an application"""
|
|
|
|
|
2024-01-04 19:39:41 +01:00
|
|
|
from os import getenv
|
|
|
|
|
2022-12-09 00:04:01 +01:00
|
|
|
from dotenv import load_dotenv
|
|
|
|
from mastodon import Mastodon
|
|
|
|
|
2023-08-01 18:59:46 +02:00
|
|
|
# ----- load .env ----- #
|
|
|
|
|
2022-12-09 00:04:01 +01:00
|
|
|
load_dotenv()
|
|
|
|
|
2023-08-01 18:59:46 +02:00
|
|
|
# ----- register application ----- #
|
|
|
|
|
2022-12-09 00:04:01 +01:00
|
|
|
Mastodon.create_app(
|
|
|
|
getenv("MASTODON_APP_NAME"),
|
|
|
|
api_base_url = str(getenv("MASTODON_URL")),
|
|
|
|
to_file = getenv("MASTODON_CLIENT_SECRET")
|
|
|
|
)
|
|
|
|
|
2023-08-01 18:59:46 +02:00
|
|
|
# ----- login Mastodon account ----- #
|
|
|
|
|
2022-12-09 00:04:01 +01:00
|
|
|
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")
|
|
|
|
)
|
|
|
|
|
2023-08-01 18:59:46 +02:00
|
|
|
# ----- post test toot ----- #
|
|
|
|
|
2022-12-09 00:04:01 +01:00
|
|
|
mastodon.toot("Hello World")
|