The getweatherforecast script will grab the current weather icon and forecast from Yahoo!, store the HTML in /tmp/weather.html, then extract and display the current and forecasted weather from the provided URL.

You will need the getweathericon script to display the icon stored in /tmp/weather.png

I'm certain that this script can be improved and I encourage suggestions.

curl --silent -o /tmp/weather.html http://weather.yahoo.com/united-states/oregon/portland-23424682/;

curl --silent -o /tmp/weather.png $(grep "div\ class=\"forecast-icon\"\ style=\"background:url" /tmp/weather.html| awk -F"'" '{ printf $2 }');for NUM in $(grep -n "<li><strong>.*\n" /tmp/weather.html|cut -d":" -f1); do TARGET=$((NUM+1)) ; sed -n "$NUM"p /tmp/weather.html|sed 's|<li><strong>||g'|sed 's|</strong>||g'| sed 's/^[\t]*//'; sed -n "$TARGET"p /tmp/weather.html ;



User Avatar
nicolasvan 3632 days ago

How do I change the city (Paris) and farenheit to celcius? I tried changing http://weather.yahoo.com/france/ile-de-france/paris-615702/ in the code but nothing come up.

User Avatar
gbblair 3613 days ago
Hello, I am using this set of geeklets, but the weather icon doesn't stay updated with the proper graphic for the weather. When it first loads after install, it shows up properly as "light snow" (with clouds and snow because of the weather today in Illinois).... However, after a few minutes it changes to partly cloudy (with a sun peeking behind the clouds). I have not changed the file path in Geektool or modified really anything.

The URL for the graphic is still: "file://localhost/tmp/weather.png". Refresh every 60 seconds. "Pick random image in directory" is not checked.

I've updated the weather to my local area and the text forecast shows up properly.

Here is the setting for the forecast:

curl --silent -o /tmp/weather.html http://weather.yahoo.com/united-states/illinois/rockford-12784473/; curl --silent -o /tmp/weather.png $(grep "div class="forecast-icon" style="background:url" /tmp/weather.html| awk -F"'" '{ printf $2 }');for NUM in $(grep -n ".*n" /tmp/weather.html|cut -d":" -f1); do TARGET=$((NUM+1)) ; sed -n "$NUM"p /tmp/weather.html|sed 's|||g'|sed 's|||g'| sed 's/^[t]*//'; sed -n "$TARGET"p /tmp/weather.html ; done

How to fix?
User Avatar
LukeHenry 3508 days ago
I love this weather geeklet . But I cannot get the weather to show Celsius in Canada. the Canadian Yahoo uses ca.weather.yahoo.com to display Celsius. this does not work with the script. omitting the ca. displays the weather correctly but with Fahrenheit.

User Avatar
ttblevins 3346 days ago
Hi, I love this geeklet, but I get the html codes appearing in the weather forecast. How can that be modified so just the weather information appears?

User Avatar
AmericanIdiot 3285 days ago
Hi, how can I change the language to portuguese and remove the [/li]'s ?
User Avatar
Russ77 3276 days ago
Sadly, another tip.

This is not meant to be a flame, but constructive criticism. This website is trying to do the community a service. I thank them.

However, the code authors and readers, in most cases, aren't aware that some of the code displayed is being mangled by this website's design. In the code display, less than signs or left angle brackets can't be used at all on this website and backslashes have to be double-backslashed to even show up as a single backslash. The designers of this website are 'apparently unaware' that they should be using some sort of 'tag' mechanism to display 'literal' 'code' 'examples' 'preformatted' so as to show us the unabridged code in the comments or elsewhere the author may want to place it on the website's webpages. I said the website designer are 'apparently unaware' because there is no prominent warning on each webpage about how inaccurate the displayed code may be.

So despite what I mentioned about copying and pasteing for accuracy, don't do it on this website, until the designers fix this webpage flaw. You can't be sure you are getting all the code unless you compare it to what is in the downloaded geeklet. You are better off just using the supplied geeklets that you can download, adapt, and implement.
User Avatar
marleyenator 3268 days ago
how can I modify this code so that I can have more than one city? I tried to change some stuff but I dont know enough to have it work. Any help is appreciated. Thanks.
User Avatar
Techie19 3238 days ago
Best weather display geeklet out there.

to find your city's code, go to weather.yahoo.com, and copy the numbers after your state and city. it should be 8 digits. great job on the .glets!
User Avatar
drwho 3233 days ago
Here is the code, modified to remove the unwanted characters from being displayed, also replace

http://weather.yahoo.com/united-states/nevada/las-vegas-2436704/ with your city's link, you can get it by looking at yahoo weather:

curl --silent -o /tmp/weather.html http://weather.yahoo.com/united-states/nevada/las-vegas-2436704/;

curl --silent -o /tmp/weather.png $(grep "div class="forecast-icon" style="background:url" /tmp/weather.html| awk -F"'" '{ printf $2 }');

LINE=$(grep -n ".*n" /tmp/weather.html|cut -d":" -f1);


for NUM in $LINE;

do TARGET=$((NUM+1)) ;

if [ $FIRST -eq 1 ]; then

sed -n "$NUM"p /tmp/weather.html | sed 's|Detailed Local ForecastHow to Read This||g' | sed 's|||g' | sed 's/^[tnn]*//';



sed -n "$NUM"p /tmp/weather.html | sed 's|||g' | sed 's|||g' | sed 's/^[t]*//';


sed -n "$TARGET"p /tmp/weather.html ;

User Avatar
bchan90 3212 days ago
@drwho Your code didn't seem to work, after copying and pasting it displayed nothing.

I decided to take a quick look at the code and coded my own fix, albeit it doesn't do it in the most efficient way, it gets the job done.  Copy and paste the following code to remove the extra html tags (and obviously change the URL to your cities URL):

curl --silent -o /tmp/weather.html http://weather.yahoo.com/united-states/california/san-luis-obispo-12796844/; curl --silent -o /tmp/weather.png $(grep "div class="forecast-icon" style="background:url" /tmp/weather.html| awk -F"'" '{ printf $2 }');for NUM in $(grep -n ".*n" /tmp/weather.html|cut -d":" -f1); do TARGET=$((NUM+1)) ; sed -n "$NUM"p /tmp/weather.html|sed 's|Detailed Local ForecastHow to Read This||g'|sed 's|||g'|sed 's|||g'|sed 's|||g'| sed 's/^[t]*//'; sed -n "$TARGET"p /tmp/weather.html ; done

User Avatar
dotcommer 3102 days ago
I reallllly want to get this to work.  No one's code seems to be working.  Everyone's code in the comments produces nothing, while the original geeklet displays html code.  Can someone PLEASE get this thing working?!
User Avatar
s_selling 2989 days ago
Thanks you so much, i had no problems, i followed the directions and poof i have a picture of my weather on my desktop, now i never have to go outside again. but really thanks for the great tool.
User Avatar
Joelw135 2987 days ago
No matter what I do it will not show, if I paste the original code it has extra html code shown. Anyone have this working without the extra code?
User Avatar
philrei 2894 days ago
very nice
User Avatar
alexwasserman 2692 days ago
I don't need the text, just the icon. I use:

curl --silent "http://weather.yahoo.com/united-kingdom/england/london-44418/" | grep current-weather | awk -F\( '{ print $2 }' | awk -F\) '{ print $1 }' | awk -F\' '{ print $2 }' | xargs curl --silent -o /tmp/weather.jpg\

Lots of awks, so computationally heavy, but not such an issue these days, and simpler to read. Could probably be replaced with one simple sed, but I prefer simple.

Log in to comment or register here.