#!/bin/bash
# grap tomdestages from taz.de
cd /web/Files2/comics/tom
YEAR="$(date +%Y)"
MONTH="$(date +%m)"
DAY="$(date +%d)"
wget --spider http://taz.de/digitaz/.tom/tomdestages
wget http://taz.de/digitaz/.tom/tomdestages?day=$YEAR/$MONTH/$DAY -O taz.temp
TEMP="$(grep alt=\"TOM taz.temp)"
TEMP2=${TEMP:97:35}
#echo $TEMP2
PIC=${TEMP2%\"*=} 
var=0$MONTH; var=${var: -2}
var=0$DAY; var=${var: -2}
NAME=$YEAR.$MONTH.$DAY
wget http://taz.de$PIC --referer=http://taz.de/digitaz/.tom/tomdestages -O $NAME.gif
#check file type, rename if jpeg type
MIME="$(file -b $NAME.gif | awk '{ print $1 }')"
if [ $MIME == "JPEG" ]; then
mv $NAME.gif $NAME.jpeg
fi
