twitter_send_tweets_command

This commit is contained in:
DaoAdvocate
2023-04-15 22:58:22 +02:00
committed by Pi
parent f785c8cf03
commit cfba3d0a60
3 changed files with 30 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import tweepy
import os
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.TweepError as e:
print("Error sending tweet: {}".format(e.reason))