SHARE
TWEET

bbcweather.sh

a guest Mar 9th, 2012 237 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/bash
  2. file=bbc.xml
  3. sfile=short_bbc.txt
  4. date=last_date.txt
  5. dir=/home/alexandr/xml/weather/almaty/bbc/
  6. sed=/home/alexandr/xml/weather/almaty/sed.bbc
  7. log=/var/log/bbc_weather.log
  8. val=values.txt
  9. wait=1800 #wait 30 minutes if date has not been updated in xml
  10.  
  11. cd $dir
  12. lastdate="`cat $date`"
  13. wget -qO - http://newsrss.bbc.co.uk/weather/forecast/140/Next3DaysRSS.xml > $file
  14. cur_date="`cat $file | grep "pubDate" | head -1 | sed -e "s/<pubDate>//g" -e "s/<\/pubDate>//g"`"
  15.  
  16. count=3
  17. while [[ ("$cur_date" == "$lastdate") && ($count > 0) ]]
  18. do
  19.   count=$[ $count-1 ]
  20.   echo "`date -R`: Date has not been updated ($count time(s) left to try): $lastdate" >> $log
  21.   if [ $count != 0 ]; then
  22.     sleep $wait
  23.     wget -qO - http://newsrss.bbc.co.uk/weather/forecast/140/Next3DaysRSS.xml > $file
  24.     cur_date="`cat $file | grep "pubDate" | head -1 | sed -e "s/<pubDate>//g" -e "s/<\/pubDate>//g"`"
  25.   else
  26.     exit
  27.   fi
  28. done
  29.  
  30. echo $cur_date > $date
  31. echo "`date -R`: New pubDate loaded: $cur_date" >> $log
  32.  
  33. count=1
  34. grep "<title\|<description" $file | grep -v "Weather Centre" | sed -f $sed > $sfile
  35. while read line
  36. do
  37.   #echo $line
  38.   OLD_IFS=$IFS
  39.   IFS=","
  40.   ar=( $line )
  41.   IFS=$OLD_IFS
  42.   if [[ ${#ar[@]} > 4 ]]; then
  43.     echo -en ${ar[2]} > $count'Wdir'
  44.       grep -q "${ar[2]}" $val || echo ${ar[2]} >> $val
  45.     echo ${ar[3]} | sed -e s/mph//g | python -c "print int(round(float(raw_input())*0.44704))" | tr -d "\n" > $count'Wspd'
  46.     echo -en ${ar[4]} > $count'Visb'
  47.       grep -q "${ar[4]}" $val || echo ${ar[4]} >> $val
  48.     #echo -en ${ar[5]} > Pressure in mb
  49.     echo -en ${ar[6]} > $count'Humd'
  50.     echo -en ${ar[7]} > $count'Sris'
  51.     echo -en ${ar[8]} > $count'Sset'
  52.     count=$[ $count+1 ]
  53.   else
  54.     #day of the week determination
  55.     case ${ar[0]} in
  56.       "Sunday")
  57.         echo -en day-0 > $count'Wday'
  58.         ;;
  59.       "Monday")
  60.         echo -en day-1 > $count'Wday'
  61.         ;;
  62.       "Tuesday")
  63.         echo -en day-2 > $count'Wday'
  64.         ;;
  65.       "Wednesday")
  66.         echo -en day-3 > $count'Wday'
  67.         ;;
  68.       "Thursday")
  69.         echo -en day-4 > $count'Wday'
  70.         ;;
  71.       "Friday")
  72.         echo -en day-5 > $count'Wday'
  73.         ;;
  74.       "Saturday")
  75.         echo -en day-6 > $count'Wday'
  76.         ;;
  77.     esac
  78.     echo -en ${ar[1]} > $count'Prec'
  79.       grep -q "${ar[1]}" $val || echo ${ar[1]} >> $val
  80.     echo -en ${ar[2]} > $count'Tmax'
  81.     echo -en ${ar[3]} > $count'Tmin'
  82.   fi
  83. done < $sfile
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top