mirror of
https://github.com/looching/cantonese_toot.git
synced 2026-04-06 03:15:02 +08:00
31 lines
675 B
Python
31 lines
675 B
Python
from mastodon import Mastodon
|
|
from loguru import logger
|
|
import random
|
|
|
|
|
|
# read all toots from file
|
|
with open('toots.txt', 'r') as f:
|
|
toots = f.read().split('\n\n')
|
|
|
|
|
|
access_token = 'your access token'
|
|
instance = 'https://mastodon.social'
|
|
mastodon_cli = Mastodon(
|
|
access_token=access_token, api_base_url=instance)
|
|
|
|
#randomly choose a toot
|
|
toot = random.choice(toots)
|
|
|
|
# post toot
|
|
try:
|
|
mastodon_cli.toot(toot)
|
|
logger.info('Toot posted, %s' % toot)
|
|
# remove toot from file
|
|
with open('toots.txt', 'w') as f:
|
|
f.write('\n\n'.join(toots))
|
|
# record toot
|
|
with open('toots_sent.txt', 'a') as f:
|
|
f.write('\n\n' + toot)
|
|
except Exception as e:
|
|
logger.error(e)
|