Bash script to display Tweets using notification daemon

So much more complicated than I thought it would be.
This should work in Gnome (Ubuntu). I've also used it in Fluxbox on the Ubuntu system.

Just place the script in your ~/bin directory. Oh, edit the User Defined Variables too. Oh, and set up a cron job.
Tell me what you think.

#!/bin/bash
###=- twitterpop -=#######################=-v0.6-=###
#                                                   #
# Displays tweets in gnome notifications            #
# To be configured as a cron job                    #
#                                                   #
###=- Dependencies -=################################
#                                                   #
# curl wget notify-send xmlstarlet                  #
#                                                   #
###=- User Defined Variables -=######################
#                                                   #
export USER=user  # local username
TWITTER_USERNAME='user'
TWITTER_PASSWORD='password'
PROXY_OCTS=10.100.17. # Looking at your IP to determine proxy
PROXY_STR="http://uname:pword@proxy:port"
DURATION=30     # Seconds to display
ADD_DURATION=10 # Additional delay per message
LIMIT=5          # Maximum tweets to display at once
#                                                   #
#####################################################
export DISPLAY=:0
GSS_PID=$(/usr/bin/pgrep -f gnome-screensaver)
export $(cat /proc/$GSS_PID/environ|tr '\0' '\n'|grep DBUS_SESSION_BUS_ADDRESS)
#=- Set proxy if necessary
if [ -n "$(/sbin/ifconfig eth0|grep $PROXY_OCTS)" ]; then
export http_proxy=$PROXY_STR
fi
INFILE=/home/$USER/bin/.tweetcache.xml
LOGFILE=/home/$USER/bin/.tweetcache.log
AVATAR_DIR=/home/$USER/bin/.twitter_avatars
let DURATION=DURATION*1000
let ADD_DURATION=ADD_DURATION*1000

#=- Exit if xscreensaver is active
if [ -n "$(/usr/bin/pgrep -f xscreensaver)" ] && [ -n "$(/usr/bin/xscreensaver-command -time|grep locked)" ]; then
exit 0
fi

#=- Exit if gnome-screensaver is active
if [ -n "$(/usr/bin/pgrep -f gnome-screensaver)" ] && [ -z "$(/usr/bin/gnome-screensaver-command -t|/bin/grep 'not currently')" ]; then
exit 0
fi

#=- Retrieve the xml feed
/usr/bin/curl --connect-timeout 10 -m 60 -u $TWITTER_USERNAME:$TWITTER_PASSWORD "http://twitter.com/statuses/friends_timeline.xml" > $INFILE

NUM_TWEETS=$(xmlstarlet sel -t -v "count(//status/text)" $INFILE)
for i in $(seq $NUM_TWEETS -1 1);
do
if [ "$DURATION" -gt $(($LIMIT * $ADD_DURATION + 20000)) ]; then
     done=1
     continue
fi
TWEETER=$(xmlstarlet sel -t -m "//status[$i]" -v "user/screen_name" $INFILE)
#=- Tweets are modified to add hyperlinks for urls and @usernames, and format some markdown (*Bold* & _Italics_)
TWEET=$(xmlstarlet sel -t -m "//status[$i]" -v "text" $INFILE|txt2html --linkonly --bold_delimiter '\*' --italic_delimiter '_' --extract --lower_case_tags|sed -r 's/strong>/b>/g'|sed -r 's/em>/i>/g'|sed -r 's/@\S*/<a href=\"http:\/\/twitter.com\/&\">&<\/a>/1g'|sed -r 's/@//')
#=-
if [ ! -d $AVATAR_DIR ]; then
mkdir $AVATAR_DIR
fi
if [ ! -e $AVATAR_DIR/$(xmlstarlet sel -t -m "//status[$i]" -v "user/profile_image_url" $INFILE|sed 's/^.*\///') ]; then
wget -P$AVATAR_DIR $(xmlstarlet sel -t -m "//status[$i]" -v "user/profile_image_url" $INFILE)
fi
AVATAR=$AVATAR_DIR/$(xmlstarlet sel -t -m "//status[$i]" -v "user/profile_image_url" $INFILE|sed 's/^.*\///')
#=- The tweet is stripped to alphanumerics, and saved to the log
SLINE=$(echo $TWEET$TWEETER|sed 's/[^a-zA-Z1-9]//g')
if [ -z $(grep $SLINE $LOGFILE) ]; then
let DURATION=DURATION+ADD_DURATION
/usr/bin/notify-send -u normal -i $AVATAR -t $DURATION -- "$TWEETER" "$TWEET"
echo $SLINE >> $LOGFILE
fi
done

#=- Shorten log file
cat $LOGFILE|tail -100 > $LOGFILE.tmp
mv $LOGFILE.tmp $LOGFILE