Guinness Premiership Geektool

I use the 'geektool' programme for Mac OS X. This lets me do lots of nice things to my desktop - information is embedded in the desktop - sometimes discretely, sometimes not. This is (approximately) what my desktop looks like now.

My Desktop

It has a twitter feed, a calendar, date and time, to do list, system specs, hard drive usage etc and a daily cartoon that updates. Since this screenshot I've added live departure times for my local train station.

I wanted to show the guinness premiership table on my desktop. So, I found a table online, download it, strip away all the surrounding info and format it for display - this then runs rarely (as the table only updates at weekends)

The result is below. It works, and I know it can probably be done more simply - but to be honest, I'm pretty pleased I got it working.

I'm sure there is a more elegant way of first identifying, then stripping out the HTML. Essentially, once I got this working on the command line, I told geektool to run it from time to time and embed the result in my desktop.

If anyone needs it, I'll shove up my train departure script too.

[sourcecode language="bash"] #!/bin/sh

cd ~/geektool/ curl --silent http://news.bbc.co.uk/sport1/hi/rugby_union/tables/4776739.stm | grep --after-context=500 -m1 'RugbyShortTable' | grep --before-context=500 -m1 '/table' | sed 's/^[[:space:]]*//g' | grep -v "^$" | tr -d '\n\r' | sed 's/r>/r>\ /g' | sed 's/r0">/r0">\ /g' > .guinnessprem

cat .guinnessprem | grep 'mvb' | sed 's/^[[:print:]]*mvb">//g' | sed 's/UK[[:print:]]*//g' > .guinnesspremdate cat .guinnessprem | grep --after-context=500 -m1 '<td class="c1">1</td>' | sed 's/<\/td>/, /g' | sed -e 's/<[^>]*>//g' | grep -v "^$" | sed 's/&nbsp;/ /' | awk -F', ' '{printf ("%2d %16s %3d %3d %3d %3d %4d %4d %3d %3d",$1,$2,$3,$4,$5,$6,$7,$8,$9,$10); print "\n"}' | grep -v "^$" > .guinnesspremtable cat .guinnessprem | grep -m1 '<td class="c1">&nbsp;</td>' | sed 's/<\/td>/, /g' | sed -e 's/<[^>]*>//g' | grep -v "^$" | sed 's/&nbsp;/ /' | awk -F', ' '{printf ("%2d %16s %3s %3s %3s %3s %4s %4s %3s %3s",$1,$2,$3,$4,$5,$6,$7,$8,$9,$10); print "\n"}' | grep -v "^$" | sed 's/^ 0 / /' > .guinnesspremheader

rm .guinnessprem

cat .guinnesspremheader > .guinness cat .guinnesspremtable >> .guinness echo " \c" >> .guinness cat .guinnesspremdate >> .guinness

rm .guinnesspremheader rm .guinnesspremtable rm .guinnesspremdate

cat .guinness [/sourcecode]

The result of all that unix trickery looks like this (as of this evening):

               Team   P   W   D   L    F    A  BP PTS
 1         Saracens  12   9   1   2  216  172   2  40
 2      Northampton  12   9   0   3  263  191   3  39
 3     London Irish  12   7   2   3  264  154   5  37
 4        Leicester  12   7   1   4  246  160   6  36
 5            Wasps  11   7   0   4  203  173   3  31
 6        Newcastle  12   4   3   5  167  184   3  25
 7       Harlequins  12   4   2   6  216  246   4  24
 8             Sale  11   4   1   6  177  212   4  22
 9       Gloucester  12   4   1   7  206  258   3  21
10             Bath  12   3   2   7  172  191   4  20
11        Worcester  12   2   4   6  169  206   3  19
12   Leeds Carnegie  12   2   1   9  154  306   4  14
               Sunday, 3 January 2010 20:12