Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- file=bbc.xml
- sfile=short_bbc.txt
- date=last_date.txt
- dir=/home/alexandr/xml/weather/almaty/bbc/
- sed=/home/alexandr/xml/weather/almaty/sed.bbc
- log=/var/log/bbc_weather.log
- val=values.txt
- wait=1800 #wait 30 minutes if date has not been updated in xml
- cd $dir
- lastdate="`cat $date`"
- wget -qO - http://newsrss.bbc.co.uk/weather/forecast/140/Next3DaysRSS.xml > $file
- cur_date="`cat $file | grep "pubDate" | head -1 | sed -e "s/<pubDate>//g" -e "s/<\/pubDate>//g"`"
- count=3
- while [[ ("$cur_date" == "$lastdate") && ($count > 0) ]]
- do
- count=$[ $count-1 ]
- echo "`date -R`: Date has not been updated ($count time(s) left to try): $lastdate" >> $log
- if [ $count != 0 ]; then
- sleep $wait
- wget -qO - http://newsrss.bbc.co.uk/weather/forecast/140/Next3DaysRSS.xml > $file
- cur_date="`cat $file | grep "pubDate" | head -1 | sed -e "s/<pubDate>//g" -e "s/<\/pubDate>//g"`"
- else
- exit
- fi
- done
- echo $cur_date > $date
- echo "`date -R`: New pubDate loaded: $cur_date" >> $log
- count=1
- grep "<title\|<description" $file | grep -v "Weather Centre" | sed -f $sed > $sfile
- while read line
- do
- #echo $line
- OLD_IFS=$IFS
- IFS=","
- ar=( $line )
- IFS=$OLD_IFS
- if [[ ${#ar[@]} > 4 ]]; then
- echo -en ${ar[2]} > $count'Wdir'
- grep -q "${ar[2]}" $val || echo ${ar[2]} >> $val
- echo ${ar[3]} | sed -e s/mph//g | python -c "print int(round(float(raw_input())*0.44704))" | tr -d "\n" > $count'Wspd'
- echo -en ${ar[4]} > $count'Visb'
- grep -q "${ar[4]}" $val || echo ${ar[4]} >> $val
- #echo -en ${ar[5]} > Pressure in mb
- echo -en ${ar[6]} > $count'Humd'
- echo -en ${ar[7]} > $count'Sris'
- echo -en ${ar[8]} > $count'Sset'
- count=$[ $count+1 ]
- else
- #day of the week determination
- case ${ar[0]} in
- "Sunday")
- echo -en day-0 > $count'Wday'
- ;;
- "Monday")
- echo -en day-1 > $count'Wday'
- ;;
- "Tuesday")
- echo -en day-2 > $count'Wday'
- ;;
- "Wednesday")
- echo -en day-3 > $count'Wday'
- ;;
- "Thursday")
- echo -en day-4 > $count'Wday'
- ;;
- "Friday")
- echo -en day-5 > $count'Wday'
- ;;
- "Saturday")
- echo -en day-6 > $count'Wday'
- ;;
- esac
- echo -en ${ar[1]} > $count'Prec'
- grep -q "${ar[1]}" $val || echo ${ar[1]} >> $val
- echo -en ${ar[2]} > $count'Tmax'
- echo -en ${ar[3]} > $count'Tmin'
- fi
- done < $sfile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement