This Python script uses the Twitter API to automatically retweet up to 5 tweets per minute containing a specified hashtag without retweeting duplicates, printing errors to avoid rate limits.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
14 views1 page
Tweepy
This Python script uses the Twitter API to automatically retweet up to 5 tweets per minute containing a specified hashtag without retweeting duplicates, printing errors to avoid rate limits.
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth)
# Function to retweet tweets containing the specified hashtag
def retweet_hashtag_tweets(): tweets = tweepy.Cursor(api.search, q=hashtag_to_search, tweet_mode='extended').items(5) for tweet in tweets: try: if not tweet.retweeted: tweet.retweet() print(f"Retweeted tweet by {tweet.user.screen_name}: {tweet.full_text}") time.sleep(5) # To avoid hitting rate limits except tweepy.TweepError as e: print(f"Error: {e.reason}")
# Run the bot
if __name__ == "__main__": while True: retweet_hashtag_tweets() time.sleep(60) # Check for new tweets every 60 seconds