0% 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.

Uploaded by

gamerwizcast
Copyright
© © All Rights Reserved
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% 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.

Uploaded by

gamerwizcast
Copyright
© © All Rights Reserved
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
You are on page 1/ 1

import tweepy

import time

# Set up your Twitter API credentials


consumer_key = 'your_consumer_key'
consumer_secret = 'your_consumer_secret'
access_token = 'your_access_token'
access_token_secret = 'your_access_token_secret'

# Set up the hashtag to search for


hashtag_to_search = '#python'

# Authenticate with Twitter


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

You might also like