Here is an example of how small scripts can give you amazing makes. Here’s my weather station using the LCD display I mentioned in my previous post: An LCD display for Raspberry Pi.

(Photos updated: April 7, 2013)

It’s displaying weather forecast for Cambridge, UK. That’s a miserable weather indeed :). As you can guess, the first line is the current condition followed by next two day’s forecast which includes high and low temperatures (in Celsius). The last line is the date and time of update.

The awesome bit is you can make this with 20 lines of scripting and in less than 5 mins. Here is how it works:

  1. Grabs the weather data from Yahoo weather feed.
  2. Extracts key weather data from the xml feed, and
  3. Displays the data to the LCD.

The whole thing is done with this shell script (which I’m sure can be further reduced a lot):

Most of the script above is for converting the rss weather feed xml into those few lines to display. It writes the information in a file which is then read and displayed to LCD by a python script. Here’s the python script to display the info in green color only:

  1. #!/usr/bin/env python
  2. from pylcdsysinfo import BackgroundColours, TextColours, TextAlignment, TextLines, LCDSysInfo
  3. from time import sleep
  4. d = LCDSysInfo(); d.clear_lines(TextLines.ALL, BackgroundColours.BLACK)
  5. d.dim_when_idle(False);d.set_brightness(127);d.save_brightness(127255)
  6. d.set_text_background_colour(BackgroundColours.BLACK)
  7. f = open(‘yw’‘r’); col = TextColours.GREEN; c = 1;
  8. for line in f:
  9.         d.display_text_on_line(c, line, False, TextAlignment.LEFT, col)
  10.  c = c + 1

That’s 20 lines of scripting doing it all! Yet another example of how awesome shell and python scripts are.

You can run this every hour simply by adding a cron job. There is a bit of details involved before you can use this code. You need the python lib for the LCD and also a bit of info on how Yahoo weather feed works: To get the forecast for your location, you need the WOEID (Google: WOEID finder) and to pass it to the Yahoo weather feed url.

I understand I should provide detailed steps for beginners, perhaps as an instructable. If you want to see the detailed steps, do let me know in the comments :).