#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo $DIR
cd $DIR
echo "" > /tmp/disclosr-error
for f in $DIR/scrapers/*.py; do
	echo "Processing $f file..";
	md5=`md5sum /tmp/disclosr-error`
	python $f 3>&1 1>&2 2>&3 | tee --append /tmp/disclosr-error;
	md52=`md5sum /tmp/disclosr-error`
	if [ "$md5" != "$md52" ]; then
		echo "^^^^^^^^^^^^^^ $f" >> /tmp/disclosr-error;
	fi
	if [ "$?" -ne "0" ]; then
		echo "error";
		sleep 1;
	fi
done
curl "localhost:5984/disclosr-foidocuments/_design/app/_view/byDate?startkey=\"9999-99-99\"&endkey=\"0000-00-00\"&descending=true&limit=20"
if [ -s /tmp/disclosr-error ] ; then
    echo "emailling logs..";
    mail -E -s "Disclosr errors" maxious@lambdacomplex.org < /tmp/disclosr-error ;
fi


