#! /usr/local/bin/bash

URL=http://weather.yahoo.co.jp/weather/jp/13/4410.html
file=4410.html
work=work.dat
data=data.dat
weather=/tmp/weather.dat

A=1; case $A in 1)
	rm -f $weather
	rm -f $work
	rm -f $file
	/usr/local/bin/wget $URL
	pointflag=0
	while read line
	do
		if echo $line | grep "<small>2004" > /dev/null
		then
			pointflag=`expr $pointflag + 1 `
		fi
		if echo $line | grep "<!---/Today--->" > /dev/null
		then
			pointflag=`expr $pointflag + 1 `
		fi
		if [ $pointflag -eq 1 ]
		then
			echo $line | /usr/local/bin/nkf -s >> $work
		fi
	done < $file
;;esac

A=1; case $A in 1)
	pointT=0
	pointflag=0
	rm -f $data
	flagd=0
	flagw=0
	while read line
	do

		if echo $line | grep "<small>2004" > /dev/null
		then
			if [ $flagd -eq 0 ]
			then
				flagd=1
				echo $line | awk '
					gsub("<small>", "")\
					gsub("</small>", "")\
					' | /usr/local/bin/nkf -s >> $data
					echo >> $data
			fi
		fi
		if echo $line | grep "<small>" > /dev/null
		then
			flagw=`expr $flagw + 1`
			if [ $flagw -eq 2 ]
			then
				echo $line | awk '
					gsub("<small>", "")\
					gsub("</small>", "")\
					' | /usr/local/bin/nkf -s >> $data
			fi
		fi

		if echo $line | grep "<td><small><font color=\"#ff3300\">最高気温(℃)\\[前日差\\]<br>" > /dev/null
		then
			echo $line | awk '
				gsub("<td><small><font color=\"#ff3300\">最高気温(℃)\\[前日差\\]<br>", "")\
                ' | /usr/local/bin/nkf -s >> $data 
	    fi
		if echo $line | grep "<td><small><font color=\"#0066ff\">最低気温(℃)\\[前日差\\]<br>" > /dev/null
		then
			echo $line | awk '
				gsub("<td><small><font color=\"#0066ff\">最低気温(℃)\\[前日差\\]<br>", "")\
                ' | /usr/local/bin/nkf -s  >> $data
	    fi

		if echo $line | grep "<td width=18%" > /dev/null
		then
			echo $line | awk '
					gsub("<td width=18%><small>", "")\
					gsub("</small></td>", "")\
					' | /usr/local/bin/nkf -s  >> $data
		fi

	done < $work
;;esac

X="℃"
rm -f $weather
i=0
while read line
do
	case  $i in
		# 日付
		"0") AA=`echo $line` ;;
		# 天候
		"1") AB=`echo $line` ;;
		# 最高温度
		"2") AC=`echo $line` ;;
		# 降水確立
		"3") AD=`echo $line` ;;
		"4") AE=`echo $line` ;;
		"5") AF=`echo $line` ;;
		"6") AG=`echo $line` ;;
		"7") AH=`echo $line` ;;
	esac
	i=`expr $i + 1 `
done < $data

echo -n "東京都の天気($AA)  " >> $weather
echo -n "………  $AB $AC$X 0-6時($AE%) 6-12時($AF%) 12-18時($AG%) 18-24時($AH%) ………                                 " >> $weather