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/README.md, 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.

Read More

Codekiddy and Open-source

I know I haven’t written a blog post in a while… so I’ve recently made an addition to my calender to try and write at least one a week, so here goes.

A few months ago I was browsing through some archived folders on my development machine and came across some old projects that I’ve worked on over the years. Unfortunately I don’t often get time to work on personal projects that much anymore, and struggle to get any work done on Clockwork, but I’d really like to start open-sourcing some of these projects.

When I say a few months ago, I actually mean about 7; time goes extremely fast when you’re trying to get on with life, most of the time I don’t even realize it.

Codekiddy

Codekiddy is a game engine I started making a few years ago for a course at University. It’s a nifty little engine written in C++, using a library called ClanLib. ClanLib isn’t so bad, it’s mostly cross-platform (although at this stage Codekiddy isn’t) and is really easy to use.

What’s cool about Codekiddy?

When I made Codekiddy (originally called Sidelined – a prototype game I was working on with a few friends before it all went downhill), I wanted it to be easy to mod. What better what to make something moddable than to implement Lua bindings, right?

  • Codekiddy uses Lua bindings for pretty much anything. It’s possible to create an entire game using the engine just from the bindings provided.
  • Codekiddy is pretty poorly documented (some text files in the project, I’d like to expand this documentation one day.)
  • LuaJIT is used to speed up Lua at run-time and works pretty well.
  • Includes a fully functional UI library written in Lua.
  • Loads content from an archived file, but content inside can be overriden by being placed in the distributed directory.
  • Includes a fully functional level editor with levels saved as JSON files (plus the ability to include a .lua script that runs specifically for that level.)
  • State system: MenuState, PlayState, etc.
  • Built-in Console (written in .lua, too, so fully customizable!)
  • Box2D physics, and entity management including base classes.
  • Built-in dynamic lighting system made by porting over box2dlights from Java to Lua.
  • Material system with material meta data in the form of custom .cmf files.

The only thing missing that I haven’t open-sourced yet is a fully working example game. I’ve actually made a couple, but I’m just trying to tidy one of them up to open-source as soon as I can.

And because I love Git so much, Codekiddy it’s freely available on GitHub. Contribute or fork as you please!

That’s all from me today, hopefully I’ll write another blog post next week, thanks guys.

Read More