#!/bin/bash
# export http_proxy=http://wr-linux01.rki.ivbb.bund.de:3128/
source /etc/local/profile.local > /dev/null

export LANGUAGE="de_DE:de:en_GB:en"
export LANG="de_DE.UTF-8"

MAILTOME=tillea@localhost

touch ~/tmp/hn-links.new
touch ~/tmp/hn-links.old
[ -s ~/tmp/hn-links.old ] && mv ~/tmp/hn-links.old ~/tmp/hn-links.old2
[ -s ~/tmp/hn-links.new ] && mv ~/tmp/hn-links.new ~/tmp/hn-links.old

#w3m -no-proxy -dump http://www.heise.de/newsticker/heise.rdf|sed -e "s/.*\(http.*[0-9]*\/\)<.*/\1/"|grep /newsticker/data > ~/tmp/hn-links.new
#w3m -no-proxy -dump_source http://www.heise.de/newsticker/ > ~/tmp/hn-links.html
## no_proxy="heise.de"
lynx -dump http://www.heise.de/newsticker/ | \
     grep "[0-9]\+\. http://www.heise.de/newsticker/.*/meldung/[0-9]\+" | \
     cut -c 7- >  ~/tmp/hn-links.new

#mail -s "HN: `date`" $MAILTOME

#echo start1

cat ~/tmp/hn-links.new ~/tmp/hn-links.old ~/tmp/hn-links.old ~/tmp/hn-links.old2 ~/tmp/hn-links.old2 |sort|uniq -u|while read a
do
	#echo $a
	~/bin/heise2.pl "$a" | lynx -dump -stdin | sed 's/^   //' > /tmp/hn_$$.txt
	#echo 1
	if [ -s /tmp/hn_$$.txt ] ; then
	    (echo $a; echo ; cat /tmp/hn_$$.txt)| \
		mailx -a "Content-Type: TEXT/PLAIN; charset=UTF-8; format=flowed" -s "HN: `head -1 /tmp/hn_$$.txt`" $MAILTOME
	    #echo 3
	    rm /tmp/hn_$$.txt
	fi
	#echo 4
done
