Your First Twitter Bot (in Python)-Part 1

Sometimes you need an excuse to learn a new programing language. For me, that language is Python and that excuse is creating a ‘bot’ for Twitter. I won’t talk about what the bot does yet, since it’s only about 40% done at this point, but I thought the experience of learning how to create it was valuable and worth sharing.

Why Python? Well Google, xkcd, and Mark Pilgrim seem to like it. For me, that’s actually good enough right there. And why Twitter? My good friends Shawn Smith and Mike Lambie think it’s a pretty cool service and will probably keep growing. So I figure it’s worth learning the Twitter APIs.

According to Wikipedia, an Internet Bot is a software application that

“performs tasks that are both simple and structurally repetitive, at a much higher rate than would be possible for a human alone”.

The bot we will create today will get a list of all the people a user is following (their “friends”) and then will compute the friends-to-followers ratio of each of those people. Why would you want to do this? Well some people (myself included) feel that a user’s ratio tells you a lot about them. Follow a lot more people than are following you, and you’ll be labeled a spammer. Really interesting people have at least as many people following them as they are following. And some of the best users on twitter maintain a close to 1:1 ratio of friends/followers. So ratio is important, and a bot that can tell us user ratios quickly might be good for other things {insert evil grin here}.

So now that we know what we want to do, we need to figure out how. If you are an experienced programmer you probably know several languages (and maybe you already know Python). You should be able to follow along fairly easily. If this describes you but you’re brand new to Python then I also recommend reading Mark Pilgrim’s book Dive Into Python. It’s available free online and full of Python-to-other-languages comparisons that make the process of learning Python very fast.

If you’re completely new to programming than have no fear, Python is a great first language. In fact, the creator of the language thought it would be useful in high schools as an introduction to programming. A great tutorial list for soon-to-be-programmers is available at the Python website.

In part 2 of this series we’ll get into the meat and potatoes of creating the bot

2 thoughts on “Your First Twitter Bot (in Python)-Part 1

  1. Bookmarked – I await part 2 with baited breath.

    Btw… you seem like a great person. xkcd, python, nice easy-to-spell name. 😉

Leave a Reply

Your email address will not be published. Required fields are marked *