mastodon-random-sentence-bot/main.py

35 lines
828 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
2023-12-08 23:17:14 +09:00
from misskey import Misskey
from dotenv import load_dotenv
from src.choose_sentence import chooseSentence
from src.generate_sentence import generateSentence
2023-12-08 23:17:14 +09:00
load_dotenv()
2023-12-03 23:01:55 +09:00
# authentication to misskey
2023-12-08 23:17:14 +09:00
misskey = Misskey(address=os.environ["MISSKEY_INSTANCE_ADDRESS"], i=os.environ["MISSKEY_ACCESS_TOKEN"])
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
random_sentence_note = misskey.notes_create(text=sentence)
note_id = random_sentence_note["createdNote"]["id"]
note_text = random_sentence_note["createdNote"]["text"]
print(f"{note_id} | {note_text}")
if __name__ == "__main__":
writeRandomSentenceNote()