#!/bin/bash

# get just once - this is not a production script.


getdata()
{
  yyyy=$1
  mm=$2
  dd=$3
  station=$4

  hh=24
  dfile=UWYO_$yyyy.$mm.$dd.txt
  rm -f tmp.html
  wget -nv -O tmp.html "http://weather.uwyo.edu/cgi-bin/wyowx.fcgi?TYPE=sflist&DATE=$yyyy$mm$dd&HOUR=$hh&UNITS=A&STATION=$station"
  html2text -o $dfile tmp.html 
}


if [[ $# -eq 0 ]]
then
  echo get_weather_uwyo.sh yyyy0 mm0 dd0 yyyy1 mm1 dd1 SSSS
  echo Fetch meteorologica data for station 'SSSS' for all days in between 
  echo yyyy0/mm0/dd0  and  yyyy1/mm1/dd1.
  exit 1
fi

y1=$1
m1=$2
d1=$3
y2=$4
m2=$5
d2=$6
station=$7

./gendate.sh $y1 $m1 $d1 $y2 $m2 $d2 > tmp.dat

nl=`cat tmp.dat | wc -l `

for il in `seq 1 $nl`
do 
  getdata ` cat tmp.dat | head -n $il | tail -n 1 ` $station
  sleep 2

done




