Friday, December 18, 2009

Samurize Config For NextBus

NextBus is a pretty awesome service but it's a pain to load up the website everytime to look up the next arrival time. The site does have bookmarkable URLs and the pages do reload automatically. But if left open the page usually times out after a few reloads. And personally, I don't like leaving tabs open in the browser for too long, it just seem untidy and unnecessary, not to mention RAM usage.

I use Samurize to embed a lot on information in 'always-on-top' panels so that I can see things like the time in 2-3 cities, the current temperature and weather conditions in my city, CPU and RAM usage, currency rates etc, all in a glance. But I couldn't find a script or plug-in that would pull the data for NextBus and NextBus doesn't have an API or even an RSS feed. I finally had some time on my hands, now that the semester has come to an end and I put together a quick-and-dirty script (in VBScript) to get the next two arrival times for a bus.

Now, I didn't have the patience to write something to parse the whole page - it's pretty messy and there's no ids or names that would make working with the HTML easier. So for now, the script is a hack that takes advantage of the fact that the page contains a block of JavaScript that sets the title of the window to the next two arrival times. So reading that and getting the time was pretty easy and works for now, at least.

You can find more details at http://www.nogoodatcoding.com/projects/nextbus-scraper. There is also a sample Samurize config, distributed as a .sam package. Here's what you should see if you use it: