Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Show a one-line weather forecast on the desktop Apps
I love Wunderground.com's forecast. You can read all of the numbers, and look at radar all you want, but 95% of the time, it's too much info. Wunderground has a one-line forecast that relates today or tomorrow's temperature to today's. "Today is forecast to be colder than yesterday" is all I need to know.

Once you've installed GeekTool, you'll also need Lynx, a popular text web browser. Once GeekTool and lynx are installed, create a new shell entry in GeekTool and enter this code, substituting in your zip code for 12345:
lynx -dump http://www.wunderground.com/cgi-bin/findweather/getForecast?query=12345|awk '/Tomorrow is/'
This will tell Lynx to go retrieve the Wunderground site and cut out every line that dosn't start with "Tomorrow is." Of course, if you check the weather in the morning, you'll need to change it to "Today is." Either way, the GeekTool entry will disappear when that text is not present. I guess you could have the weather appear in different places on your desktop depending on wether it's forecasting today or tomorrow, but that's left as an exercise to the reader.

[robg adds: I tried this, and it works as described. It's probably possible with curl instead of lynx, but you'd then need to do more parsing of the output to strip out the HTML characters. Given this data probably won't change during the day, you should set the GeekTool refresh to a really large value.]
    •    
  • Currently 1.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[31,574 views]  

Show a one-line weather forecast on the desktop | 18 comments | Create New Account
Click here to return to the 'Show a one-line weather forecast on the desktop' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Show a one-line weather forecast on the desktop
Authored by: rammjet on Nov 18, '08 09:45:40AM
Using curl:
curl -s http://www.wunderground.com/cgi-bin/findweather/getForecast?query=12345 | awk '/Today is/ || /Tomorrow is/' | textutil -convert txt -stdin -stdout -format htm
'textutil' converts the 'html' output to 'text'.   It is a very versatile command.

Modifying the 'awk' command allows it to handle both 'Today' and 'Tomorrow' conditions

Both 'curl' and 'textutil' are included with Mac OS X

[ Reply to This | # ]

Show a one-line weather forecast on the desktop
Authored by: Anonymous on Nov 18, '08 11:30:00AM

-format html, not -format htm -- the latter kicks back "invalid input format".



[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: rammjet on Nov 19, '08 09:40:38AM
Yes, sorry, it was a typo. The "l" in "html" must have gotten dropped while playing around with formatting.   klaus has displayed it correctly along with piping it to growl.

[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: kopf on Nov 18, '08 08:35:19PM
If you have Growl and growlnotify installed try this, adapted from above: curl -s http://www.wunderground.com/cgi-bin/findweather/getForecast?query=12345 | awk '/Today is/ || /Tomorrow is/' | textutil -convert txt -stdin -stdout -format html | growlnotify

[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: codeProle on Nov 20, '08 05:35:28AM

When I run the script (with 'html') all I get is "Error reading -stdin"

I've tried typing the script myself and copy-pasting it into Terminal.

Help!



---
--
15" G4 TiBook 867MHz 768 MB 100 GB .:. 10.4.4



[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: mbroughtn on Nov 18, '08 09:46:20AM

You really don't need to install GeekTool. The command works fine from the Terminal once Lynx is installed. You could even create an alias for the full command and have something like 'lynxweather' expand to the full command.



[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: rammjet on Nov 19, '08 09:43:58AM

GeekTool allows the results to be displayed embedded into the Desktop.   It can rerun the command periodically.   No need to have Terminal open or displayed.



[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: tterragcnoom on Nov 18, '08 09:59:57AM

I use a perl script to pull the same xml file that the apple weather widget pulls from weather.com. I then parse this and use the images from the weather widget and paste that on my desktop with geektool. I also used imagemagick to composite images together (clouds over different moon phases).



[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: Anonymous on Nov 18, '08 12:03:26PM

That's a lot of effort to go to when you could just drop the widget on your desktop.



[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: Sigma on Nov 18, '08 05:10:40PM

This sounds great (and much more versatile and attractive than a weather widget), would you mind sharing your methods?



[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: Doc Drang on Nov 18, '08 10:08:11AM
Weather info seems like a natural for GeekTool. My GeekTool weather command gets the current conditions from a nearby NOAA station and puts it in the lower left corner of my screen. Handy to check before running out the door when you've been office-bound for several hours.

http://www.leancrew.com/all-this/2007/04/more-desktop-weather-with-geektool/

---
Doc Drang
http://www.leancrew.com/all-this

[ Reply to This | # ]

Show a one-line weather forecast on the desktop
Authored by: dsjkvf on Nov 18, '08 11:11:42PM

yes, your solution is indeed very nice (i've been using a slightly modified version for a while), but the only problem is that it reports _current_ weather conditions, and not the real weather forecast :).



[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: dsjkvf on Nov 18, '08 11:02:41PM
yeah, nice answer
Today is forecast to be nearly the same temperature as yesterday.
:)

[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: anika123 on Nov 20, '08 05:07:39PM
I use lynx dump and WU to get instant weather updated every six seconds.

I use this command: lynx -dump -width 120 http://printer.wunderground.com/cgi-bin/findweather/getForecast?query=21719 | /Users/lloncosky/library/scripts/lee/weathergeekA

With this script called weathergeekA:

#!/usr/bin/env perl

# Grab all the lines and put in an array.
@w = <>;

# Keep only certain lines for the current conditions.
@t = grep /^ +(Temperature|Wind|Humidity|Conditions|Updated|Observed|Pressure)/, @w;

# Erase the leading spaces and parenthetical values.
for (@t){s/^ +//;s/\(\)//g};

# I want the temperature line to print on the bottom to make it
# easy to see on the desktop. The temperature is always on the
# second line, so exchange it with the last line.
# ($t[$#t], $t[1]) = ($t[1], $t[$#t]);

# Sometimes there's a windchill line, and sometimes there isn't.
# Add a blank line to the front of the array if there isn't.
unshift @t, "\n" if $#t == 2;

# Print the lines of interest in the order I want.
print join "", @t;



You can change the script to get the facts you want. I have geektool display 8 lines in the bottom left of my desktop. I always have an accurate outdoor temp and wind direction.

[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: anika123 on Nov 20, '08 05:17:27PM

I forgot to mention. This works best when you use the cookies feature in lynx to select the rapid fire weather station nearest to you. I think you need to install a newer lynx to get the cookies. Then use lynx in the terminal to goto your zipcode weather underground site. Then scroll down and select your favorite local rapid fire station and set it as your default. Thats it. Now whenever lynx dumps the page you will get the weather closest to you.



[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: loren_ryter on Jan 03, '10 08:34:48AM
that printer. URL no longer works it seems (maybe just temporary but...) This mobile link works instead ok:
/sw/bin/lynx -dump -width 120 http://m.wund.com/cgi-bin/findweather/getForecast?query=48103#conditions | ~/bin/geektool/weathergeek
However I have a perl question... In the perl script above, how can the part that erases "leading spaces and parenthetical values" be modified so that it also kills everything after " / " (space slash space) -- that is all the metric values given? Because my output now looks like this:

Temperature 13.4?F / -10.3?C
Windchill 13?F / -10?C
Humidity 73%
Wind NNW at 3.0 mph / 4.8 km/h
Conditions Clear
Sunset 5:15 PM EST


[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: anika123 on Jan 03, '10 03:16:04PM

I will work on that. In the mean time see my new python script in the main thread. Its not as good but I had not even looked at the mobile site, thanks for pointing that out. You will have to open the new script and change the weather code to reflect your area. Maybe it is useful to you. If not, look at it in a text editor and change at will. Everything is commented.



[ Reply to This | # ]
Show a one-line weather forecast on the desktop
Authored by: anika123 on Jan 03, '10 03:38:03PM

It has been a good run but the weather underground printing Web site seems to have died. When it happened I figured I would just transition my weather scripts over to their official xml api. Long story short, I am now using python and weather undergrounds xml api to get my weather into geektool, nerdtool. It is not as good because they do not have cool stuff like conditions, sunset or lunar stuff in their xml data. Maybe someone else can shed more lite on how they scrape the WU mobile site.

Here is the code.

<code>-------------------------cut here
#! /usr/bin/env python

# cobbled together by Lee Loncosky 2009 from readings on the web

import sys
import urllib
# from optparse import OptionParser
from xml.dom.minidom import parse

# get the url for my local station and put it in variable 'url'

#first we need to select the closest online pws station from the location area api
# parse the url with minidom looking in this order for the closest pws which
# will always be the first 'id' element that is run across, the sequence goes
# <location>
# <nearby _weather_stations>
# <pws>
# <id>
# </id>,</pws>,</nearby_weather_stations>,</location>
wu_urlarea = 'http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=21719'
urlarea = wu_urlarea
domarea = parse(urllib.urlopen(urlarea))
wu_idpws = domarea.getElementsByTagName('id')[0]
wu_idpws = wu_idpws.toprettyxml()
wu_idpws = str(wu_idpws)
wu_idpws = wu_idpws.strip("<id>\n")
wu_idpws = wu_idpws.strip("</id>\n")
wu_idpws = wu_idpws.replace("![CDATA[","")
wu_idpws = wu_idpws.replace("]]","")
wu_idpws = wu_idpws.strip()
wu_url = 'http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID='
wu_url = wu_url+wu_idpws
wu_url.strip()
# finally pass the current closest pws station to wu_url and then to url to get the current observation api
url = wu_url
# parse the url (xml) with minidom
dom = parse(urllib.urlopen(url))

# get location first
# grab the location which is a child element of current_observation and put into variable
current_node = dom.firstChild
location_node = current_node.childNodes[7]
wu_location = location_node.childNodes[1]

# grab the xml elements that we want to use and put into variables
wu_time = dom.getElementsByTagName('observation_time')[0]
wu_temp = dom.getElementsByTagName('temperature_string')[0]
wu_wind = dom.getElementsByTagName('wind_string')[0]
wu_pressure = dom.getElementsByTagName('pressure_in')[0]

# start with first variable and turn into type string and then strip the xml <tags/>

wu_location = wu_location.toprettyxml()
wu_location = str(wu_location)
wu_location = wu_location.strip("<full>\n")
wu_location = wu_location.strip("</full>\n")
# replace the crazy charaters with white space. Only needed on location and pressure_string
wu_location = wu_location.replace("&quot;","")
wu_location = wu_location.strip()

wu_time = wu_time.toprettyxml()
wu_time = str(wu_time)
wu_time = wu_time.strip("<observation_time>\n")
wu_time = wu_time.strip("</observation_time>\n")
wu_time = wu_time.strip()

wu_temp = wu_temp.toprettyxml()
wu_temp = str(wu_temp)
wu_temp = wu_temp.strip("<temperature_string>\n")
wu_temp = wu_temp.strip("</temperature_string>\n")

wu_wind = wu_wind.toprettyxml()
wu_wind = str(wu_wind)
wu_wind = wu_wind.strip("<wind_string>\n")
wu_wind = wu_wind.strip("/<wind_string>\n")
wu_wind = wu_wind.strip()

wu_pressure = wu_pressure.toprettyxml()
wu_pressure = str(wu_pressure)
wu_pressure = wu_pressure.strip("<pressure_in>\n")
wu_pressure = wu_pressure.strip("/<pressure_in>\n")

# print everything to screen with labels

print wu_location
print wu_time
print 'Temp',wu_temp
print wu_wind
print 'Pressure',wu_pressure
<code>--------------------------------------------cut here

You will have to change the following line to reflect your zipcode.

wu_urlarea = 'http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=21719'

Hope it works. If not please modify to suit your needs.

All the standard stuff applies... make it executable, make sure python is in your path, make sure to give whole path in geektool, nerdtool ... etc...
















[ Reply to This | # ]