config.py 723 B

123456789101112131415161718192021222324
  1. # tweepy-bots/bots/config.py
  2. import tweepy
  3. import logging
  4. import os
  5. logger = logging.getLogger()
  6. def create_api():
  7. consumer_key = os.getenv("CONSUMER_KEY")
  8. consumer_secret = os.getenv("CONSUMER_SECRET")
  9. access_token = os.getenv("ACCESS_TOKEN")
  10. access_token_secret = os.getenv("ACCESS_TOKEN_SECRET")
  11. auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  12. auth.set_access_token(access_token, access_token_secret)
  13. api = tweepy.API(auth, wait_on_rate_limit=True,
  14. wait_on_rate_limit_notify=True)
  15. try:
  16. api.verify_credentials()
  17. except Exception as e:
  18. logger.error("Error creating API", exc_info=True)
  19. raise e
  20. logger.info("API created")
  21. return api