#!/bin/sh
#
BASE_URL="http://www.weather.gov/xml/current_obs"

usage () {
  echo "Usage:  $0 <station> [ <station> ... ]"
  exit 1
}

date=`date -u '+%y%m%d'`
hour=`date -u '+%H'`

stations=""
while [ "$#" -gt 0 ]; do
  case $1 in 
        -*)  
             echo "unrecognized option: $1"
             usage;;
    [A-Z][A-Z0-9][A-Z0-9][A-Z0-9]) 
             stations="$stations $1"
             shift;;
  esac
done

if [ -z "$stations" ]; then
  usage
fi

for name in $stations; do
  file="$name-${date}-${hour}Z.xml"
  echo "Downloading observations for station $name into $file"
  curl -s -S -R "$BASE_URL/${name}.xml" -o "$file"
done

