Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ for more details.
As the traffic cam keeps taking photos every 5 minutes, the number of files in the archive directory quickly adds up, over the past 2 months there were around 12 thousand files. This was getting a little bit difficult to manage so I decided that it would be a good idea if the script automatically put these into directories sorted by year, month and day.

The change is quite simple, the line where the ARCH_DIR variable is set is changed to this:
ARCH_DIR=$WORK_DIR/wbrsew/`date +"%Y"`/`date +"%m"`/`date +"%d"`
mkdir -p $ARCH_DIR


The whole script looks like this now (I also changed from Wacaw to ImageSnap):
#!/bin/bash
WORK_DIR=/Users/ikromin/Downloads
ARCH_DIR=$WORK_DIR/wbrsew/`date +"%Y"`/`date +"%m"`/`date +"%d"`
mkdir -p $ARCH_DIR
WACAW="/Users/ikromin/Downloads/wacaw-04/wacaw --png -d 2 -n 3 $WORK_DIR/wbrsew_o"
ISNAP="/Users/ikromin/Downloads/ImageSnap-v0.2.5/imagesnap -w 1 $WORK_DIR/wbrsew_o.png"
CONVERT=/usr/local/bin/convert
OPTIM=/Applications/ImageOptim.app/Contents/MacOS/jpegoptim
if [ ! -d "$ARCH_DIR" ]; then
mkdir $ARCH_DIR
fi
#$WACAW
$ISNAP
$CONVERT $WORK_DIR/wbrsew_o.png -adaptive-resize 640x480> -unsharp 0x1 $WORK_DIR/wbrsew_o.jpeg
cp $WORK_DIR/wbrsew_o.jpeg $ARCH_DIR/arch_`date +"%Y%m%d%H%M%S"`.jpeg
$CONVERT $WORK_DIR/wbrsew_o.jpeg -sharpen 0x.4 $WORK_DIR/wbrsew_s.jpeg
$CONVERT $WORK_DIR/wbrsew_s.jpeg -font Arial -pointsize 14 -draw "gravity south-west fill '#00000090' rectangle 0,480 640,450 fill black text 11,8 'Riverside Expressway Cam © Igor Kromin' fill white text 10,7 'Riverside Expressway Cam © Igor Kromin' gravity south-east fill black text 11,8 'Time: `date`' fill white text 10,7 'Time: `date`' gravity north-west fill '#00000090' rectangle 0,0 640,24 fill white text 6,4 'Visit: http://www.igorkromin.net/?page=wbrsew'" $WORK_DIR/wbrsew.jpeg
$OPTIM --strip-all -m85 $WORK_DIR/wbrsew.jpeg
scp $WORK_DIR/wbrsew.jpeg [email protected]:/dir/




-i

Skip down to comments...
A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. If you spot something out of place, please do let me know.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
 
comments powered by Disqus
Other posts you may like...