bioneural.net site preferences

Accessibility

Toggle width/ text size:

style

Default/Alternate

Suits visual impairment, mobile devices

Styling

Change the theme:

layout

Sorry, this option is not enabled

Link behaviour

Links with an icon are off-site:

links

Right-click any link to optionally open in a new window or tab


 

Live BBC weather using GeekTool

GeekTool is great fun and seems an ideal means of occupying the mind while avoiding something else you should be doing. This Preference Pane for OS X basically lets you create a "live" desktop, auto-updating with data extracted using shell scripts (which can themselves call AppleScripts), image overlays, or log and other text files. I found many inspiring examples around the web to appropriate for my own desktop (see here; apologies for failing to note sources)—but one thing I had to work out by trial-and-error was bringing BBC Weather into the mix.

Assuming you already have GeekTool installed (free), go download and install Lynx, a command-line web browser available for OS X here (free).

Now enter your town, city, country or UK post code on the BBC Weather website. Look for the "latest observations feed" link. For example, for Chesterfield the feed link is:

http://feeds.bbc.co.uk/weather/feeds/rss/obs/id/3282.xml

In GeekTool create a new shell script with the following command:

lynx -dump http://feeds.bbc.co.uk/weather/feeds/rss/obs/id/3282.xml

This will show you the text file that we will be working with, created from the RSS feed. Alternatively you might open the same URL in Lynx itself from the Terminal:

lynx.jpg

In a TextEdit window (for editing convenience) we now write AWK commands to search for and pull out the bits we want. I found these articles served as a useful AWK primer. You can also search-and-replace text as in the following code to remove redundant commas:

{gsub(/,/,"")};

Find a unique word on each line from which you want to extract text. For example, to refer to the line containing "Temperature:", you might use "Temp" enclosed within forward slashes:

/Temp/

Now count the words left to right in that line of text (see image above); the third word in would be represented by the $3 variable (in this case the temperature in Celsius). You can add text in quote marks as a prefix or suffix to any variable, separating them using commas. For example:

/Temp/{print "Temp:",$3};

This would return something like:

Temp: 11°C

With a bit of effort you can construct a one-line command that displays all relevant data on your desktop. For example:

lynx -dump http://feeds.bbc.co.uk/weather/feeds/rss/obs/id/3282.xml | awk '{gsub(/,/,"")}; /Temp/{print "Temp:",$3}; /Wind/{print "Wind:",$4,$7,$8}; /Humid/{print "Humidity:",$11}; /Press/{print "Barometer:",$2,$3}; /Visib/{print "Visibility:",$5,$6}; /Broad/{print "Chesterfield","@",$7}'

You should end up with a "live" desktop that looks something like this:

bbc.jpg

9 responses to Live BBC weather using GeekTool


  1. 1 Emme

    This. Is. Awesome.

    Thankye for sharing!

  2. 2 Peter

    Thanks for this, I was just looking for one for the UK - all the GeekTool tips on macosxhints.com are US-centric! Well done ;)

  3. 3 Frederick Sarran

    Hi,

    Nice but cannot find RSS feed link URL for Aberdeen. What I have is http://news.bbc.co.uk/weather/forecast/14/ObservationsRSS.rss and of course is different from what you have, As well, it does not work.

    Please help ?

  4. 4 Bruce

    Interesting Frederick; it looks as though they have changed the latest observations feed URL—although I am still receiving data (only subtly different) using the old URL.

    I'm not sure what you mean by "it doesn't work" because in Terminal (after installing Lynx as noted) the command lynx -dump followed the above URL and return does return the appropriate data for me. Then it's a case of matching fixed text to the position of the data variable in the line. So, for Aberdeen, this works:

    lynx -dump http://news.bbc.co.uk/weather/forecast/14/ObservationsRSS.rss | awk '{gsub(/,/,"")}; /Temp/{print "Temp:",$3}; /Direct/{print "Wind:",$2,$5}; /Humid/{print "Humidity:",$8}; /Visib/{print "Barometer:",$1,$2}; /Visib/{print "Visibility:",$4,$5}; /57.2/{print "Aberdeen","@",$1}'
    

    Likewise, using the new URL for Chesterfield, the command becomes:

    lynx -dump http://news.bbc.co.uk/weather/forecast/4271/ObservationsRSS.rss | awk '{gsub(/,/,"")}; /Temp/{print "Temp:",$3}; /Direct/{print "Wind:",$3,$6}; /Humid/{print "Humidity:",$9}; /Press/{print "Barometer:",$2}; /Visib/{print "Visibility:",$5,$6}; /-1.25/{print "Chesterfield","@",$1}'
    

  5. 5 John Crumpton

    Great article - but can I get this working on Windows?

  6. 6 Bruce

    Not using GeekTool John, which doesn't exist for Windows. However, Lifehacker recommend an equivalent PC app called Samurize.

  7. 7 Iain Shaw

    Brilliant, thanks for sharing this. Re-ignited my curiosity in awk as well.

  8. 8 Foe

    this is sweet! Any chances that it would work with curl instead of lynx? Thanks man!

  9. 9 Phil

    Hi,

    Nice, but I cant get the code working in geektool. It works fine in terminal though

    Thanks

Something to say?

Comments may be moderated, are subject to spam filtering, and should be inoffensive and relevant to this post. Please disclose commercial interests.

Usable tags include <a href=""> <blockquote> <em>.