mastodon-random-sentence-bot/main.py

35 lines
808 B
Python
Raw Normal View History

2023-12-08 23:17:14 +09:00
import os
2023-12-03 23:01:55 +09:00
import random
2024-07-04 18:11:04 +09:00
from mastodon import Mastodon
2023-12-08 23:17:14 +09:00
from dotenv import load_dotenv
from src.choose_sentence import chooseSentence
from src.generate_sentence import generateSentence
2024-07-04 18:11:04 +09:00
load_dotenv()
2023-12-08 23:17:14 +09:00
2023-12-03 23:01:55 +09:00
# authentication to misskey
2024-07-04 18:11:04 +09:00
mastodon = Mastodon(access_token="token.secret", api_base_url=os.environ["MASTODON_INSTANCE_ADDRESS"])
2023-12-03 23:01:55 +09:00
def writeRandomSentenceNote():
choice_methods = [
chooseSentence,
generateSentence
]
2023-12-03 23:01:55 +09:00
# choose method and get sentence
sentence: str = random.choice(choice_methods)()
2023-12-05 19:33:42 +09:00
2023-12-03 23:01:55 +09:00
# write note
2024-07-04 18:11:04 +09:00
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}")
2023-12-03 23:01:55 +09:00
if __name__ == "__main__":
writeRandomSentenceNote()