wviewweather.com Forum Index wviewweather.com
wview and Weather Topics
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Dealing with timestamped images

 
Post new topic   Reply to topic    wviewweather.com Forum Index -> Web Sites and HTML Templates
View previous topic :: View next topic  
Author Message
chrisale



Joined: 09 Nov 2005
Posts: 187

PostPosted: Sun Dec 18, 2005 9:55 pm    Post subject: Dealing with timestamped images Reply with quote

I've added some satellite, jetstream and radar images to my frontpage.

The first two were easy, the radar was a bit more involved because rather than simply updating a single temporary image, Enviroment Canada stores the temporary radar images individually, by time, every 10 minutes.

SO I had to create a UNIX shell script running "sed" to search and replace the URL of the image every 10 minutes. Once I figured out the regular expression to do it... it was fairly straight forward, the hardest part was dealing with the time formats that get their zeros stripped off after doing a math operation on them.

Anyway. Here's the shell script, I run it in a cron job on the 10s and the output goes to a log file:

Code:

#/bin/sh

## First grab dates in UTC format (-u operator).  Minute and Hour must
## be in double digit format.

curyear=`date -u +%G`
curday=`date -u +%d`
curmonth=`date -u +%m`
curhour=`date -u +%H`
curminute=`date +%M`

#Store filename prefix and extension
preword='XSI_CAPPI_'
postword='.GIF'

#Store modulus of the current minute. 
#We will only update every 10 minutes on the 10s.
#Radar image is delayed by about 10 minutes..
#thus we'll subtract 10 from current minute.
#Also, in case its' the top of the hour, we'll need to store the previous hour.

minmod10=`expr "$curminute" % 10`
oldminute=`expr "$curminute" - 10`
prevhour=`expr "$curhour" - 1`


echo ''
echo 'Starting Radar Script'
echo 'Current UTC Time'
echo "$curyear-$curmonth-$curday,$curhour:$curminute"



if ( test $minmod10 -eq 0 )
then
   if ( test "$curhour" -le 10 )
   then
      case "$oldminute" in
         -10)
         if ( test "$prevhour" -le 10 )
         then
            sed 's/'"$preword"'\(.\)\{4\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}'"$postword"'/'"$preword$curyear"'_'"$curmonth"'_'"$curday"'_0'"$prevhour"'_50'"$postword"'/g' /etc/wview/html/index.htx > /etc/wview/html/temp   
            mv /etc/wview/html/temp /etc/wview/html/index.htx
            echo 'Its top of hour, and GMT is less than or equal to 10.  We need to add a 0 to the hour.'
         else
            sed 's/'"$preword"'\(.\)\{4\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}'"$postword"'/'"$preword$curyear"'_'"$curmonth"'_'"$curday"'_0'"$prevhour"'_50'"$postword"'/g' /etc/wview/html/index.htx > /etc/wview/html/temp   
            mv /etc/wview/html/temp /etc/wview/html/index.htx
            echo 'Its top of hour, and GMT is greater than 10. So we need the prevhour but no 0 before.'
         fi
         ;;
         0)
            sed 's/'"$preword"'\(.\)\{4\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}'"$postword"'/'"$preword$curyear"'_'"$curmonth"'_'"$curday"'_0'"$curhour"'_00'"$postword"'/g' /etc/wview/html/index.htx > /etc/wview/html/temp   
            mv /etc/wview/html/temp /etc/wview/html/index.htx
            echo 'Its 10 minutes past.  So replace the single 0 in oldminute with double 00 instead'
         ;;
         *)
            sed 's/'"$preword"'\(.\)\{4\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}'"$postword"'/'"$preword$curyear"'_'"$curmonth"'_'"$curday"'_0'"$curhour"'_'"$oldminute$postword"'/g' /etc/wview/html/index.htx > /etc/wview/html/temp   
            mv /etc/wview/html/temp /etc/wview/html/index.htx
            echo 'Its somewhere between 20 and 50 this is the easy part.'
         ;;
      esac
   else
      case "$oldminute" in
         -10)
         if ( test "$prevhour" -le 10 )
         then
            sed 's/'"$preword"'\(.\)\{4\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}'"$postword"'/'"$preword$curyear"'_'"$curmonth"'_'"$curday"'_0'"$prevhour"'_50'"$postword"'/g' /etc/wview/html/index.htx > /etc/wview/html/temp   
            mv /etc/wview/html/temp /etc/wview/html/index.htx
            echo 'Its top of hour, and GMT is less than or equal to 10.  We need to add a 0 to the hour.'
         else
            sed 's/'"$preword"'\(.\)\{4\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}'"$postword"'/'"$preword$curyear"'_'"$curmonth"'_'"$curday"'_'"$prevhour"'_50'"$postword"'/g' /etc/wview/html/index.htx > /etc/wview/html/temp   
            mv /etc/wview/html/temp /etc/wview/html/index.htx
            echo 'Its top of hour, and GMT is greater than 10. So we need the prevhour but no 0 before.'
         fi
         ;;
         0)
            sed 's/'"$preword"'\(.\)\{4\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}'"$postword"'/'"$preword$curyear"'_'"$curmonth"'_'"$curday"'_'"$curhour"'_00'"$postword"'/g' /etc/wview/html/index.htx > /etc/wview/html/temp   
            mv /etc/wview/html/temp /etc/wview/html/index.htx
            echo 'Its 10 minutes past.  So replace the single 0 in oldminute with double 00 instead'
         ;;
         *)
            sed 's/'"$preword"'\(.\)\{4\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}_\(.\)\{2\}'"$postword"'/'"$preword$curyear"'_'"$curmonth"'_'"$curday"'_'"$curhour"'_'"$oldminute$postword"'/g' /etc/wview/html/index.htx > /etc/wview/html/temp   
            mv /etc/wview/html/temp /etc/wview/html/index.htx
            echo 'Its somewhere between 20 and 50 this is the easy part.'
         ;;
      esac
   fi
   echo 'done sed'
else
   echo 'Nothing to do.'
fi
 
echo 'Changing Permissions'
chmod 775 /etc/wview/html/index.htx
echo done
Back to top
View user's profile Send private message MSN Messenger
bhnb



Joined: 28 Nov 2005
Posts: 127

PostPosted: Mon Dec 19, 2005 6:08 pm    Post subject: Reply with quote

Hi Chris

It's probably over-cautious for this application but I always try to make just one call to 'date' so that the results are consistent, and the day/minute/month/year/whatever hasn't rolled over between the first and last calls.

This would set your variables in a safer way:

eval "`date -u "+curyear=%Y curday=%d curmonth=%m curhour=%H curminute=%M"`"

It's based on the example at http://cfaj.freeshell.org/shell/tuesday-tips/#tt-2004-06-29


Cheers

Jon
Back to top
View user's profile Send private message
chrisale



Joined: 09 Nov 2005
Posts: 187

PostPosted: Wed Dec 21, 2005 10:42 am    Post subject: Reply with quote

I never thought of that... good suggestion, I'll add that in.

I've also debugged the script a lot now that it's had a chance to go through a few daily cycles... I'll update the code above when I'm 99% sure it's "stabilized", that said the code above is 90% functional.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    wviewweather.com Forum Index -> Web Sites and HTML Templates All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group