misskey-random-sentence-bot/main.py

35 lines
808 B
Python

import os
import random
from mastodon import Mastodon
from dotenv import load_dotenv
from src.choose_sentence import chooseSentence
from src.generate_sentence import generateSentence
load_dotenv()
# authentication to misskey
mastodon = Mastodon(access_token="token.secret", api_base_url=os.environ["MASTODON_INSTANCE_ADDRESS"])
def writeRandomSentenceNote():
choice_methods = [
chooseSentence,
generateSentence
]
# choose method and get sentence
sentence: str = random.choice(choice_methods)()
# write note
toot = mastodon.toot(sentence)
toot_url = toot["url"]
toot_content = toot["content"]
toot_created_at = toot["created_at"]
print(f"{toot_created_at} {toot_url} : {toot_content}")
if __name__ == "__main__":
writeRandomSentenceNote()