twitter_main.py 993 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/python3
  2. import tweepy
  3. from randstrip import createStrip,readConfig
  4. import os
  5. import sys
  6. fileDir = os.path.dirname(os.path.abspath(__file__))
  7. fileDir = fileDir +"/"
  8. if __name__ == "__main__":
  9. if len(sys.argv) == 2:
  10. altProfile = [sys.argv[1]]
  11. else:
  12. altProfile = False
  13. config = readConfig(platform="twitter",profile=altProfile)
  14. status = createStrip(config)
  15. if status == 0:
  16. with open(config["token"]) as f:
  17. tokens = f.readlines()
  18. tokens = [x.strip() for x in tokens]
  19. auth = tweepy.OAuthHandler(tokens[0],tokens[1])
  20. auth.set_access_token(tokens[2],tokens[3])
  21. api = tweepy.API(auth)
  22. published = False
  23. for i in range(0,100):
  24. try:
  25. api.verify_credentials()
  26. api.update_with_media(config["saveLocation"]+config["filename"],config["text"])
  27. published = True
  28. os.remove(config["saveLocation"]+config["filename"])
  29. except:
  30. continue
  31. break
  32. if not(published):
  33. print("Auth error")
  34. else:
  35. print("Error creating image\n")
  36. print(status)