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

Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...