26 lines
849 B
Python
26 lines
849 B
Python
from mastodon import Mastodon
|
|
from os.path import exists
|
|
from os import chmod, stat
|
|
from stat import ST_MODE
|
|
|
|
def getmod(fn):
|
|
return stat(fn)[ST_MODE] & 0777
|
|
|
|
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")
|
|
chmod("clientcred.secret",0600)
|
|
elif getmod("clientcred.secret")!=0600:
|
|
chmod("clientcred.secret",0600)
|
|
tmp = Mastodon(client_id="clientcred.secret",api_base_url="https://tilde.zone")
|
|
with open("details.secret") as f:
|
|
tmp.log_in(f.readline().strip(),f.readline.strip(),to_file="usercred.secret")
|
|
chmod("usercred.secret",0600)
|
|
elif getmod("usercred.secret")!=0600:
|
|
chmod("usercred.secret",0600)
|
|
|
|
m = Mastodon(access_token='usercred.secret',api_base_url="https://tilde.zone")
|
|
|
|
def toot(msg):
|
|
m.toot(msg)
|