Python Twitter bot part 7

Python Twitter bot part 7

                                      Python Twitter Bot Part 7

Hey guys, Welcome to the part 7 of twitter bot. In the previous article we have learnt how to create the Auto like twitter bot. Now we will learn how to build an useful bot i.e. Retweet bot. When we want to retweet every tweet which contain a string related to something which we want, instead of searching every tweet and retweeting them, we can just use this Retweet bot to do all the work for us.

Code of Retweet twitter bot:

import tweepy
#enter your keys here
#enter your keys here
#to establish connection
#assigned our twitter home timeline
information to the variable public_tweets.
search_string="VARUN DEEPAK" #String you want to search
15 #number of tweets you want to retweet
for tweet in tweepy.Cursor(,search_string).items(numberoftweets): try: tweet.retweet() print(" I retweeted the tweet") #print statement for us to know that bot has
retweeted the tweets successfully except tweepy.TweepError as e: print(e.reason) #exception of tweep error and also prints the error reason except StopIteration: break #exception for iteration error and breaks the iteration

In the above code, the bot searches for the tweets containing the word "VARUN DEEPAK" and retweets them but it only retweets 15 tweets containing that word as we have mentioned in the code.

This is the end of Twitter Bot. For more interesting articles please visit my profile.