mastodon_main.py 894 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python3
  2. from randstrip import createStrip,readConfig
  3. from mastodon import Mastodon
  4. import os
  5. fileDir = os.path.dirname(os.path.abspath(__file__))
  6. fileDir = fileDir +"/"
  7. API_URL = "https://botsin.space"
  8. if __name__ == "__main__":
  9. config = readConfig(platform="mastodon")
  10. with open(config["token"]) as f:
  11. createapp = f.readlines()
  12. createapp = [x.strip() for x in createapp]
  13. TOKEN = createapp[0]
  14. mastodon = Mastodon(access_token = TOKEN,api_base_url = API_URL)
  15. status = createStrip(config)
  16. if status == 0:
  17. published = False
  18. for i in range(1,100):
  19. try:
  20. new_strip = mastodon.media_post(config["saveLocation"]+config["filename"],"image/png")
  21. mastodon.status_post("Nuova striscia",media_ids=new_strip)
  22. published = True
  23. except:
  24. continue
  25. break
  26. if not(published):
  27. print("Auth error")
  28. else:
  29. print("error creating image\n")
  30. print(status)