twitter_main.py 863 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python3
  2. import tweepy
  3. from randstrip import createStrip,readConfig
  4. import os
  5. fileDir = os.path.dirname(os.path.abspath(__file__))
  6. fileDir = fileDir +"/"
  7. if __name__ == "__main__":
  8. config = readConfig(platform="twitter")
  9. status = createStrip(config)
  10. if status == 0:
  11. with open(config["token"]) as f:
  12. tokens = f.readlines()
  13. tokens = [x.strip() for x in tokens]
  14. auth = tweepy.OAuthHandler(tokens[0],tokens[1])
  15. auth.set_access_token(tokens[2],tokens[3])
  16. api = tweepy.API(auth)
  17. published = False
  18. for i in range(0,100):
  19. try:
  20. api.verify_credentials()
  21. api.update_with_media(config["saveLocation"]+config["filename"],"Generatore automatico di strip. Striscia di oggi.")
  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)