Download autogpt/commands/twitter.py from Coderteq/AutoGPT: direct link, hf CLI and curl.
- Browser
- Download file 743 Bytes
-
https://huggingface.co/spaces/Coderteq/AutoGPT/resolve/main/autogpt/commands/twitter.py
- Command line
-
hf download hf://spaces/Coderteq/AutoGPT/autogpt/commands/twitter.py
-
curl -L -o twitter.py https://huggingface.co/spaces/Coderteq/AutoGPT/resolve/main/autogpt/commands/twitter.py
743 Bytes
| import os | |
| import tweepy | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| def send_tweet(tweet_text): | |
| consumer_key = os.environ.get("TW_CONSUMER_KEY") | |
| consumer_secret = os.environ.get("TW_CONSUMER_SECRET") | |
| access_token = os.environ.get("TW_ACCESS_TOKEN") | |
| access_token_secret = os.environ.get("TW_ACCESS_TOKEN_SECRET") | |
| # Authenticate to Twitter | |
| auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
| auth.set_access_token(access_token, access_token_secret) | |
| # Create API object | |
| api = tweepy.API(auth) | |
| # Send tweet | |
| try: | |
| api.update_status(tweet_text) | |
| print("Tweet sent successfully!") | |
| except tweepy.TweepyException as e: | |
| print("Error sending tweet: {}".format(e.reason)) | |