Unread Count Tracking

This is a collection of scripts for tracking unread count (I'm musing other things, though) across various online services that I use, so I can easily see how swamped I am with data this week.

250) { $list = array_slice( $list, -250 ); } $max = max($list); $last = $list[ count($list) - 1 ]; // scale values from 0-100 (ewwww) then trim to 2dp for ($i=0; $i

Here, live, I present the last week or so of my little data-driven universe:

instapaper unread items">
read it later unread items">
inbox total size">
google reader unread items">

There's two parts to the code - a periodically run set of monitors, and a web front end.

The monitoring scripts are written in ruby, my go-to language for scripting this year. Each monitored service gets its own script. There's a little shared code because I have a single config file and output format, but mostly they're very specialist things. For instance, the core of the IMAP inbox size counter looks approximately like:

imap = Net::IMAP.new( server, port )
imap.login( username, password )

imap.examine('INBOX')
total = imap.search(["NOT", "DELETED"]).length
imap.disconnect

File.open(output_file, "a") {|f| f.puts total }

Of course, that's just IMAP. The Instapaper unread counter has to screen-scrape the web site, so has to keep track of cookies and things, but this is pretty much a detail - the core of the scripts all get a count from somewhere, and write it out to a file. The result is 3 text files on disk with a single number per line.

I run the scripts once an hour from cron. This gives me three files on disk that describe recent unread counts - one service per file, one unread count per line. My kind of database.

The front-end scripts are almost as simple. I have two versions, a PHP version for that nice 'it just works and doesn't bother me' feeling, and a pure-JavaScript version for when I'm feeling uneasy about running server-side code again, though it is a little pickier about where the data files are written. The scripts just grab the data files, read all the lines out, trim to the last week's worth of data, and then build a Google Chart API url and stuff it into an image tag. I don't bother with any server-side image building, all that stuff is so 90s. Tip of the hat to style.org for a lovely set of sparkliney settings.

The code is, naturally, available on Github, along with approximate installation instructions and example cron scripts. Let me know if you use it for anything.

© 2012