11

Load and display Yahoo weather

Posted in Weather by scheme 540 days ago

[Admin note: I've updated the Geeklet files so the scripts are embedded within them, so you can just download them and not worry about saving any scripts. Loadweather.glet is an invisible geeklet that just grabs the weather information from Yahoo and saves it in a file called weather.dat in your documents folder. You can change this if you want. I also had to modify the other two scripts to get them in a form that would work while embedded in a geeklet file, so they don't match what is shown below.]

I use this script to load weather info from Yahoo in every minute to a file, which I use then to fetch details to the other scripts displaying the details. The script:

#!/bin/bash
#loading weather information to weather.dat / I set geektool to do this every 1 minute
#replace "000000" with your city code (you can find it if you go to the site) and "u=c" with "u=f" if you wish to have Fahrenheit data
curl --silent "http://xml.weather.yahoo.com/forecastrss?w=000000&u=c" > /usr/bin/scheme/weather.tmp
#if no data available (e.g. net is down), use the previously dowloaded data instead of creating a file with 0 bytes
if [ "`ls -l /usr/bin/scheme/weather.tmp | awk '{print $5}'`" != "0" ]
then
mv /usr/bin/scheme/weather.tmp /usr/bin/scheme/weather.dat
fi

Then, data is retrieved from this file. E.g., for displaying current temperature in "21 C" format, I use:

#! /usr/bin/perl
$line=`grep "yweather:condition" /usr/bin/scheme/weather.dat`;
if ($line =~ /(temp=")(.+?)(")/) {print $2," C"} else {print "xx C";}

And I display the textual info, with different color above the temperature with this:

#! /usr/bin/perl
$line=`grep "yweather:condition" /usr/bin/scheme/weather.dat`;
if ($line =~ /(text=")(.+?)(")/) {print $2;}

I also prepared small scripts for sunrise, sunset and forecasts, each in different .pl to enable using different fonts. From the XML info is quite easy to fetch: if you need to have wind speed info just grep yweather:wind and speed inside and there you go.

Geeklet files to download

Comments

User Avatar
Arthgallo 296 days ago
Wind Speed..........

 

Echo Wind Speed

grep "yweather:wind" ~/Documents/weather.dat | awk '{ print $4 }' | awk 'BEGIN { FS = "["]" } ; { print $2 " MPH"}'

 

Log in to comment or register here.