#!/usr/bin/env bash

if [ "$1" == "" ]; then
	year=`date '+%Y'`
	mon=`date '+%m'`
	day=`date '+%d'`
else
	year=$1
	mon=$2
	day=$3
fi

fpath="/data/daily_dashboard/comparison/median/od550_dust/${year}/${mon}/${year}${mon}${day}_median_loop.gif"
echo $fpath

while [ 1 == 1 ]
do
	if test -f $fpath; then
		echo "$fpath found!"
		cp $fpath /tmp/bdrc_animation.gif
		convert -geometry 800x /tmp/bdrc_animation.gif /tmp/bdrc_animation.gif
		break
	else
		echo "$fpath NOT found"
		sleep 300
	fi
done

wait

# upload to Plone
cd /data/web/zeocluster
sudo -u plone_buildout ./bin/client2 run ./bin/upload_home_loop.py &> /tmp/upload_home_loop.log

# remove again
rm -f ${HOME}/tmp/*_image??.png
