


Creating a twitter rss bot code#
The most important part of this code is the line api.update_with_media(img, reply, in_reply_to_status_id = tweet_id). Here is a simplified version of the code: class listener(StreamListener): def on_status(self, data): tweet = data.text tweet_id = data.id user = _name # Avoid tweets not made by of of the victims if user.lower() not in victims or "RT in tweet: pass else: reply, img = memeficator(tweet) # If user didn't tweet any text if reply is None: pass else: reply = " api.update_with_media(img, reply, in_reply_to_status_id = tweet_id) return(True) twitterStream = Stream(auth, listener()) twitterStream.filter(follow=victims_ids) The first one does a basic cleaning (removes weird characters, mentions, hashtags, etc.) and the second one returns the tweet modified in a mocking way and an image (the Sponge Bob meme).įinally, I created a listener class to be on the lookout for new tweets made by our victims. Next, I created two functions: text_clean and memeficator. I obtained the user id numbers with this page since I only had a few victims, but you can Pythonize this step as well. Then we need to create two lists, one with our victims’ usernames and another one with our victims’ user id numbers. First, we need to authenticate in the following way: # Authenticate through the API auth = tweepy.OAuthHandler(api_key, api_secret_key) t_access_token(access_token, access_token_secret) api = tweepy.API(auth) We are going to use Tweepy, a Python library to connect to the Twitter API. So, for example, if our victim says “I like avocado toast”, the bot will reply “i LiKe AvOcAdO tOaSt” with a Sponge Bob meme. The way the bot is going to work is that as soon as one of our victims tweets, the bot will instantly reply with a new tweet mocking theirs. The complete code is available on GitHub, but let’s explore the main functionalities of this script.
Creating a twitter rss bot free#
For this bot, I used a t2.micro EC2 instance from AWS but feel free to use whichever you want. You can get a developer account with your existing Twitter account, but keep in mind that then the bot will post tweets from your account. The most up-to-date Python version (I recommend using Anaconda).In order to be able to follow this blog post, you will need three things: First of all, if you want to practice your Spanish, here is a fun video where I tell you what happened when I trolled my friends with this bot followed by a tutorial.
