Twitter Contest Bot

“This is the story of how I wrote a Twitter bot to automatically enter contests and ended up winning on average 4 contests per day, every day, for about 9 months straight.” – Hunter Scott

Recently Hunter Scott, an American programmer and Electrical Engineer at Motorola Solutions, wrote a post on his blog about using a bot to win over 1,000 contests on Twitter by re-tweeting contest tweets. The story broke on various news article such as Engadget, the Independent, and the Guardian.

Like so many who read about this story, I immediately realized how amazing it is that nobody had done this before. So in a state of complete boredom I decided to quit procrastinating and conduct a bit of research on the Twitter API and see how quickly I could whip up a similar bot using Python.

A little bit about Python

Prior to this experiment I hadn’t used Python too much, so I had to familiarize myself with its syntax. After an hour or so of tinkering around I had created a script – that although very basic – accomplished the same fundamental result as Hunter’s bot.

Whilst coding with Python I came to realize how pleasant it is for a few good reasons:

  1. Python uses indentation for scope. Instead of using curly braces (or then, end, and do in Lua), you simply use tabs to denote where a block begins or ends.
  2. You don’t need to provide parenthesis around the arguments of a function call, and while I’ve seen this in other languages too, it’s nice for simple methods that take only a string.
  3. The package manager “pip” is lovely to use, and very quick to get started on a new script and import any necessary dependencies.

How does it work?

The Twitter API for Python is used to scan new tweets for keywords like “RT to win” every 10 seconds (to adhere to Twitter’s request limits), and are added to a queue.

r = api.request('search/tweets', {'q':'RT to win', 'since_id':last_twitter_id}) for item in r: if item['retweet_count'] > 0: post_list.append(item)

Then, every 5 seconds, the first item in the queue is re-tweeted. The content of the post is analyzed to figure out whether it is required to be favourited, or for the author to be followed.

if len(post_list) > 0: post = post_list[0] CheckForFollowRequest(post) CheckForFavoriteRequest(post) api.request('statuses/retweet/:' + str(post['id']))

Where can I find this bot?

This bot is written purely for educational purposes. I hold no liability for what you do with this bot or what happens to you by using this bot. Abusing this bot can get you banned from Twitter, so make sure to read up on proper usage of the Twitter API.

If you’re interested in checking out the source code, you can find it over at the twitter-contest-bot repository on GitHub. From the time of this posting it has been Starred by users 53 times and Forked over 25 times. Two GitHub users have already contributed to it through pull-requests and I expect more will probably do the same.

Yesterday night I received an e-mail from GitHub user raulrene, he was letting me know that he too had created a similar bot (coded with JavaScript) in response to the news. You can find his bot here. I have sinced included a link to it under the Alternatives section of twitter-contest-bot/, and he has done the same.

I posted a link to the bot on Reddit in response to a post about Hunter’s bot; it very quickly received over 300 upvotes from users, and garnered way more attention I thought it would. R.I.P. my inbox.

In conclusion, Python is cooler than I thought and writing bots is pretty fun.

Subscribe to kurozael's blog

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]