mastodon_main.py 999 B

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