#!/bin/bash

#set up file names and such

PAGE =reddit.com / .json

TEMPFILENEW =speaker.tmp

TEMPFILEOLD =speakerprev.tmp

DIFFFILE =diff.tmp

SPEAKME =speakthis.tmp

#overwrite the old headlines with the newer ones

mv $TEMPFILENEW $TEMPFILEOLD

#get the latest news and make it readable

wget --quiet $PAGE -O $TEMPFILENEW

sed -i 's/created_utc/

/g' $TEMPFILENEW

sed -i 's/^.*title"://g' $TEMPFILENEW

sed -i 's/^.*}}//g' $TEMPFILENEW

sed -i 's/[\"|\\|,$]//g' $TEMPFILENEW

#now figure out what has changed since our last update

diff -iw $TEMPFILEOLD $TEMPFILENEW > $DIFFFILE

egrep '^>' $DIFFFILE > $SPEAKME

sed -i 's/^>//g' $SPEAKME

#print it out and speak it

echo "The latest headlines:"

cat $SPEAKME