[MLUG] Re: getting the current temperature
Stephen Montgomery-Smith
stephen at math.missouri.edu
Sun Oct 28 13:07:36 CDT 2007
Actually the easiest way is to use the KDE or GNOME desktops, and use
the built in weather apps.
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).
>
> Mike
>
>
> #!/usr/bin/bash
>
> export default_zip=55406
>
> if [ "$#" = "0" ]; then
> export zip=$default_zip
> else
> export zip=$1
> fi
>
> gdate +"Current time: %b %d, %l:%M %P %Z" | perl -pe 's/ +/ /g'
>
> lynx -source "http://forecast.weather.gov/zipcity.php?inputstring=$zip"
> | gegrep -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
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> members mailing list
> members at mlug.missouri.edu
> http://mlug.missouri.edu/mailman/listinfo/members
More information about the members
mailing list