twitter_main.py 933 B

12345678910111213141516171819202122232425262728293031323334353637
  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. except:
  29. continue
  30. break
  31. if not(published):
  32. print("Auth error")
  33. else:
  34. print("Error creating image\n")
  35. print(status)