mirror of
https://github.com/looching/cantonese_toot.git
synced 2026-04-05 19:05:00 +08:00
feat(send.py, toots.txt): 导出所有俗语,增加发送脚本
导出所有俗语,增加发送脚本 Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
commit
0954918fe3
30
send.py
Normal file
30
send.py
Normal file
@ -0,0 +1,30 @@
|
||||
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)
|
||||
Loading…
x
Reference in New Issue
Block a user