#!/bin/bash

# wminfo plugin: monitors weather report and weather forecasts

# command: wminfo -p conky.wrapper-weather.wmi -u 6 -i 1 -b#000000 -f#00ffff

# the script based on an idea by Peter Trenholme

#
# CONFIGURATION SECTION BEGINS HERE
#

command[1]="conky.weather.wmi EPWR"
command[2]="conky.weather.wmi EPWR"
command[3]="conky.forecast.wmi WROCLAW, PL"
command[4]="conky.forecast.wmi WROCLAW, PL"
Steps="4"
Manual_Mode="off"

#
# CONFIGURATION SECTION ENDS HERE
#

datafile="$HOME/.wminfo/conky.tmp"
name=${0//*\//}
name=${name/.wmi/}
tempfile="$HOME/.wminfo/.counter.$name.tmp"
plugin="$0"

exit="no"

for n in `seq 1 $Steps`
do
    if [ "`which ${command[$n]} 2> /dev/null`" == "" ]
    then
	echo "${plugin}: put ${command[$n]} plugin into PATH."
	exit="yes"
    fi
done

if [ "$exit" == "yes" ]
then
    echo -e "         \n         \n         \n         \n"
    exit
fi

plugin=".${plugin//*\/}"

if [ ! -e $tempfile ]
then
    step=0
    echo step=$step > $tempfile
fi

. $tempfile

if [ "$Manual_Mode" == "off" ] || [ -e "$HOME/.wminfo/$plugin" ]
then
    if [ $step -ge $Steps ]
    then
	step=0
	echo step=$step > $tempfile
    fi

    step=$((step + 1))
    echo step=$step > $tempfile

    if [ -e "$HOME/.wminfo/$plugin" ]
    then
	rm "$HOME/.wminfo/$plugin"
    fi
elif [ "$Manual_Mode" == "on" ]
then
    if [ $step -eq 0 ]
    then
	step=1
	echo step=$step > $tempfile
    fi
fi

${command[$step]}

echo "         "

