Wicked Cool Shell Scripts
Wicked Cool Shell Scripts :: shell script 063-weather.sh

Shell Script 063-weather.sh

#!/bin/sh

# weather - report weather forecast, including lat/long, for zip

llurl="http://www.census.gov/cgi-bin/gazetteer?city=&state=&zip="
wxurl="http://wwwa.accuweather.com"
wxurl="$wxurl/adcbin/public/local_index_print.asp?zipcode="

if [ "$1" = "-a" ] ; then
  size=999; shift
else 
  size=5
fi

if [ $# -eq 0 ] ; then
  echo "Usage: $0 [-a] zipcode" >&2
  exit 1
fi

if [ $size -eq 5 ] ; then
  echo ""

  # get some information on the zipcode from the Census Bureau
  
  lynx -source "${llurl}$1" | \
    sed -n '/^<li><strong>/,/^Location:/p' | \
    sed 's/<[^>]*>//g;s/^ //g'
fi

# the weather forecast itself at accuweather.com

lynx -source "${wxurl}$1" | \
  sed -n '/Start - Forecast Cell/,/End - Forecast Cell/p' | \
  sed 's/<[^>]*>//g;s/^ [ ]*//g' | \
  uniq | \
  head -$size

exit 0

Explore The Book!
[book cover]
Table of Contents
Read Some Scripts!
Shell Script Library
Book Errata
All The Links
Read the Reviews
Talk About It
Author Bio
Buy The Book!



Other books by author Dave Taylor
Learning Unix for Mac OS X (O'Reilly & Associates)
Solaris 9 for Dummies (Wiley)
Teach Yourself Unix in 24 Hours (Sams/Macmillan)
Teach Yourself Unix System Administration in 24 Hours (Sams/Macmillan)
Creating Cool HTML 4 Web Pages (Wiley)
Ten Quick Steps to Learning Mac OS X Unix (ebook!)