mastodon-random-sentence-bot/main.py

33 lines
869 B
Python
Raw Normal View History

2023-12-03 23:01:55 +09:00
from misskey import Misskey
import random
from src.setting import instance_address, access_token
from src.choose_sentence import chooseSentence
from src.generate_sentence import generateSentence
2023-12-03 23:01:55 +09:00
# authentication to misskey
misskey = Misskey(address=instance_address, i=access_token)
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
# change newline-character to be valid
sentence = sentence.replace("\\n", "\n")
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()