Writing a Twitter Bot for Fun and Profit

One of my first thoughts when Twitter had its IPO was that the days of writing Twitter bots was over. My fear was that they would lock down their platform in order to more accurately sell ads.

Man, was I wrong.

The Twitter API is still as robust as ever and allows for creating Twitter bots. One of the current trends is to try to generate buzz around a product or idea by getting people to use a specific hashtag. This can often lead to slightly hilarious results, such as the Face of MLB. Basically, the fans “vote” for their favorite player to be the Face of MLB by using a certain hashtag. I cannot think of a better job for a twitter bot.

Setting up a bot or Twitter Application is easy, just go to Twitter Apps and login or create a new username and log in. Follow the steps and you can get an API key in a few minutes. Although note that in order to write tweets as a bot you have to choose Read + Write (instead of the default Write). I run my bot largely using the tweepy Python library which provides easy access to the Twitter API. Here is a gist of a bot I am running for the Face of MLB. Twitter does not allow the same tweet to be posted more than once from an account so I just add something like the current time:

I will admit this is kinda silly, but if I can’t use my programming skills to get someone like Eric Sogard elected the Face of MLB, then what’s the point of programming?