Weather Script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Listers,
A few days ago I posted a crude script for obtaining the current weather.
Below is a revised version which allows you to enter either a zipcode or
city, state.  The output is piped into the flite synthesizer.  If you don't
have flite you can remove the it and have the output sent to the console.
You can also change what info is spoken by modifying the awk program.  

Chris

##### weather script below this line #####

#!/bin/sh
#  The following script uses lynx to retrieve the 
#  weather for the entered zipcode or city/state.
#  A simple awk program selects the fields to be displayed.
case $# in
    0) echo "Usage:"
       echo "    wx <zipcode>"
       echo "  or" 
       echo "    wx <city>,  <state>"
       exit;;
    1) query=$1;;
    2) query=${1/%,}%2C+$2\";;
esac
lynx -dump http://braille.wunderground.com/cgi-bin/findweather/getForecast?query=${query}|\
awk ' \
/Updated:/ {u1 = $2; u2 = $3}
/Observed/ {print $1, $2, $3, $4, "at", u1, u2} 
/Temperature/ {t = $2
    gsub(/[^[:digit:]]/, "", t)
    print $1, t}
/Humidity/ {print $1, $2} 
/Dew Point/ {t = $3
    gsub(/[^[:digit:]]/, "", t)
    print $1, $2, t}
/Wind/ {w = $2
    if (length(w) <= 3) {
        gsub(/N/, "North ", w)
        gsub(/S/, "South ", w)
        gsub(/E/, "East ", w)
        gsub(/W/, "West ", w)
    }
    print $1, w, $3, $4}' | flite




[Index of Archives]     [Linux for the Blind]     [Fedora Discussioin]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]
  Powered by Linux