Python Twitter bot part 6














































Python Twitter bot part 6



                                          Python Twitter Bot Part 6

Hey guys, Welcome to the part 6 of twitter bot. In the previous article we have learnt how to create the follow back followers twitter bot. In this article, we will learn how to build an auto like twitter bot. With the help of this bot, we can search all the tweets containing a particular string and automatically like them. Here, we have to assign that string to the bot and also we have to pre-define the number of tweets, the bot have to search and like.

Code of Auto like twitter bot:

import tweepy
auth=tweepy.OAuthHandler(consumer_key,consumer_secret)
#enter your keys here
auth.set_access_token(access_token,access_token_secret)
#enter your keys here
api=tweepy.API(auth)
#to establish connection
public_tweets=api.home_timeline()
#assigned our twitter home timeline
information to the variable public_tweets.
search_string="VARUN DEEPAK" #String you want to search
numberoftweets=
15 #number of tweets you want to like
for tweet in tweepy.Cursor(api.search,search_string).items(numberoftweets):
try:
tweet.favorite()
print(
" I liked the tweet") #print statement for us to know that bot has liked 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 likes them but it only likes 15 tweets containing that word as we have mentioned in the code.

We will learn about Retweet twitter bot in the next article.


Comments