[MLUG] Re: getting the current temperature
Mike Miller
mbmiller at taxa.epi.umn.edu
Sun Oct 28 13:12:14 CDT 2007
On Sun, 28 Oct 2007, Mike Miller wrote:
> That was kinda lame so I did go back and fix it. Here's a much better
> script, now in Bash, that you can use. Just change the default_zip on the
> first line. You can now do things like this:
>
> temp 31792
>
> To get the current temperature in that zip code. It pumps out some other
> stuff too, but to make it easy to change how it works, I listed the perl
> output variables at the end. So you can change the this bit...
>
> Last updated: $2\n$1\n$3 $4 ($5)
>
> To get different kinds of output formats. For example, changing it to
> this...
>
> $4
>
> ...would give you nothing but the Fahrenheit temperature (and the current
> time which is automatically pumped out earlier in the script -- you could
> comment that out if you wanted).
Use the one below. Small change: The last time I was using "gdate" and
"gegrep" instead of date and egrep. This is because I put a 'g' in front
of the filenames to get the GNU versions on my Solaris machine. So the
g's are removed below and it should work.
Mike
#!/usr/bin/bash
export default_zip=55406
if [ "$#" = "0" ]; then
export zip=$default_zip
else
export zip=$1
fi
date +"Current time: %b %d, %l:%M %P %Z" | perl -pe 's/ +/ /g'
lynx -source "http://forecast.weather.gov/zipcity.php?inputstring=$zip" | egrep -A3 '^<td><span class="blue1">' | perl -pe 'BEGIN{undef $/} s@<td><span class="blue1">(.+?)</span><br>.+?<br>Last Update on (.+?)<br>.+align="center">(.*?)<br><br>(.+?)<br>\((.+?)\)</td>@Last updated: $2\n$1\n$3 $4 ($5)@s ; s/°/°/g'
# Perl output variables:
#
# $1 = weather station location
# $2 = last update time
# $3 = weather condition (e.g., Fair)
# $4 = degrees F
# $5 = degress C
More information about the members
mailing list