2020-12-29 02:13:29 +01:00
|
|
|
#!/usr/bin/python3
|
2020-12-17 01:31:57 +01:00
|
|
|
from randstrip import createStrip,readConfig
|
2019-09-23 00:38:07 +02:00
|
|
|
from mastodon import Mastodon
|
2019-09-25 12:35:05 +02:00
|
|
|
import os
|
2020-12-29 02:13:29 +01:00
|
|
|
import sys
|
2019-09-23 15:33:03 +02:00
|
|
|
|
2019-09-24 13:26:31 +02:00
|
|
|
fileDir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
fileDir = fileDir +"/"
|
2019-09-23 15:33:03 +02:00
|
|
|
API_URL = "https://botsin.space"
|
|
|
|
|
2022-04-30 00:54:16 +02:00
|
|
|
def publishStrip(altProfile=False,user=False):
|
2020-12-29 02:13:29 +01:00
|
|
|
config = readConfig(platform="mastodon",profile=altProfile)
|
2020-12-17 01:31:57 +01:00
|
|
|
with open(config["token"]) as f:
|
2019-09-23 00:38:07 +02:00
|
|
|
createapp = f.readlines()
|
|
|
|
createapp = [x.strip() for x in createapp]
|
2019-09-23 15:33:03 +02:00
|
|
|
TOKEN = createapp[0]
|
|
|
|
mastodon = Mastodon(access_token = TOKEN,api_base_url = API_URL)
|
2020-12-17 01:31:57 +01:00
|
|
|
status = createStrip(config)
|
2019-09-23 00:38:07 +02:00
|
|
|
if status == 0:
|
2020-03-25 15:11:26 +01:00
|
|
|
published = False
|
|
|
|
for i in range(1,100):
|
|
|
|
try:
|
2020-12-17 01:31:57 +01:00
|
|
|
new_strip = mastodon.media_post(config["saveLocation"]+config["filename"],"image/png")
|
2022-04-30 00:54:16 +02:00
|
|
|
if not(user):
|
|
|
|
mastodon.status_post(config["text"],media_ids=new_strip)
|
|
|
|
else:
|
|
|
|
mastodon.status_post(user+" "+config["text"],media_ids=new_strip,visibility="direct")
|
2020-03-25 15:11:26 +01:00
|
|
|
published = True
|
|
|
|
except:
|
|
|
|
continue
|
|
|
|
break
|
|
|
|
if not(published):
|
|
|
|
print("Auth error")
|
2019-09-23 00:38:07 +02:00
|
|
|
else:
|
|
|
|
print("error creating image\n")
|
2019-09-23 15:33:03 +02:00
|
|
|
print(status)
|
2022-04-30 00:54:16 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if len(sys.argv) == 2:
|
|
|
|
publishStrip([sys.argv[1]])
|
|
|
|
else:
|
|
|
|
publishStrip()
|