cosmicbot/toot.py

26 lines
858 B
Python
Raw Normal View History

2020-09-11 01:18:42 +00:00
from mastodon import Mastodon
from os.path import exists
from os import chmod, stat
from stat import ST_MODE
def getmod(fn):
2020-09-11 02:23:29 +00:00
return stat(fn)[ST_MODE] & 0o777
2020-09-11 01:18:42 +00:00
if not exists("usercred.secret"):
if not exists("clientcred.secret"):
Mastodon.create_app("cosmicbot toots",api_base_url="https://tilde.zone",to_file="clientcred.secret")
2020-09-11 02:23:29 +00:00
chmod("clientcred.secret",0o600)
elif getmod("clientcred.secret")!=0o600:
chmod("clientcred.secret",0o600)
2020-09-11 01:18:42 +00:00
tmp = Mastodon(client_id="clientcred.secret",api_base_url="https://tilde.zone")
with open("details.secret") as f:
2020-09-11 02:24:47 +00:00
tmp.log_in(f.readline().strip(),f.readline().strip(),to_file="usercred.secret")
2020-09-11 02:23:29 +00:00
chmod("usercred.secret",0o600)
elif getmod("usercred.secret")!=0o600:
chmod("usercred.secret",0o600)
2020-09-11 01:18:42 +00:00
m = Mastodon(access_token='usercred.secret',api_base_url="https://tilde.zone")
def toot(msg):
m.toot(msg)