Visualizing our running progress

You’ve found a dinosaur, this post is only here for archiving purposes. The content is outdated and is not applicable anymore.

While I was running a couple of weeks back I was thinking about Nike’s new slogan for it’s Nike+ campaign. “Make it count!” it says, but for what? So I hacked up a little website that fetches all tweets send by the Nike+ app and bundles all our runs together per hour.

Make it count! is the result. It holds a realtime visualisation which displays all runs reported by Twitter as circles. Big circles are big runs, etc.. You can also see the top hour of today (since midnight GMT). Every hour get’s a score and our goal is to top that score every hour!

The site is built almost entirely in javascript, node.js catches all tweets and sends them over realtime by using web sockets (socket.io). You can read more about that in my previous blogpost.

The site does need some improvement in the design, I’ve already talked to some people about helping me out here. So stay tuned for even more awesomeness!

Storing tweets using nodejs

Since I have my own VPS I’m constantly trying out new stuff. After messing around with nodejs I have my own little script (just over 100 lines) that connects to Twitter using their streaming API, get’s all tweets that contain certain words, do a minimal amount of parsing and store it all in a SQL database.

Nodejs does not contain a lot of stuff out of the box which I need, the power lies in the huge amount of ‘modules’ (extenstions) for node. They even got their own package manager! In this example I use the modules node-mysql, ntwitter and forever.

Installing all those couldn’t be easier:

npm install mysql ntwitter forever

In my script I fetch all tweets by people who use nikeplus (app) to keep track of their running results. By storing all those tweets I can later create something cool with all the data. I use the streaming API to keep a connection open, to do this you need to register your own app at dev.twitter.com to get the required keys.

Setup:

var sys = require('util');

/* setup mysql connection */
var Client = require('mysql').Client;
var client = new Client();
client.user = 'sql username';
client.password = 'sql password';
console.log('Connected to MySQL');

Now we have a we have twit object for opening a Twitter stream and a client object for talking to our SQL server.

more