lynx -width=100000 \ -dump ‘http://mobile.wunderground.com/cgi-bin/findweather/getForecast?brand=mobile&query=32605’ |\ sed ‘1,/Forecast as of/d; s#^ ##g’ |\ head -5 |\ egrep “.$” |\ head -1
Note: the only line breaks in the above are where you see \ or |\
What it does:
1) lynx dumps the output of the web page. Change ‘32605’ to the zip code you want. Note the ‘-width’ flag which is crucial to making this work. It is meant to ensure that no line breaks will be added unless the HTML code calls for it.
2) sed deletes from the first line down to where it finds ‘Forecast as of’ and deletes the leading spaces.
3) head takes the first 5 lines
4) egrep grabs the lines which end with a period
5) head takes the first result, which is the current weather conditions
So I can check out the current weather at any time with a simple command. Turning it into a shell script that takes a variable is simple enough, I’d probably make it something like this:
!/bin/sh
if [ "$#" -lt 1 ] then # set a default zip code ZIP=45631 else # you can use either a zip code or words such as # gainesville florida # but you need to replace any spaces with + ZIP=
echo "$@" | tr -s ' ' '+'fiURL=”http://mobile.wunderground.com/cgi-bin/findweather/getForecast?brand=mobile&query=$ZIP”
echo -n “Current weather for $ZIP: “
lynx -width=100000 -dump “$URL” |\ sed ‘1,/Forecast as of/d; s#^ ##g’ |\ head -5 |\ egrep “.$” |\ head -1
exit 0
EOF