(Updated Wed Nov 21 12:50:42 PST 2001)

There used to be an awful mess of bad shell code, crontabs to drive it, bad locks that didn't work, etc. The below is a bit better.

To my horror, Wonko stumbled across this ugly beast (after he had wnitten his own), & linked it from E2 Chatterbox Archive.

Anyway, in hopes that no one ever actually read the old one, here is something slightly less embarrasing.


This is pretty self contained. It checks for new messages every $INTERVAL seconds, logs to $LOGFILE, & kicks out plantext readable output on stdout.

(Note: "fetch" is used to grab chatter. If your unix doesn't have a fetch, alter $GET appropiately.)

#!/bin/sh

URL="http://www.everything2.com/index.pl?node=chatterbox%20XML%20ticker"
GET="fetch -o - -q"
LOGFILE="$HOME/chatterbox.log.html"
TMPFILE="/var/tmp/`basename $0`a.$$"
TMPFILE2="/var/tmp/`basename $0`b.$$"
INTERVAL="60"

# Note:  This isn't an XML parser.  It's a big ugly hack.

trap cleanup 1 2 3 15

cleanup () {
 rm -f $TMPFILE $TMPFILE2 
 exit 
}

parsemsg () {
 while read line;do
  nick=`echo "$line"|cut -d\" -f2`
  nick=`echo "<a href=\"http://www.everything2.com/?node=$nick\">$nick</a>"`
  date=`echo "$line"|cut -d\" -f4|sed "s/..$/.&/"`
  date=`date -j $date +%T`
  line=`echo "$line"|sed "s/^[^>]*>//"|sed "s%</message>.*%%"`
  if echo "$line"|grep "^/me" >/dev/null;then
   line=`echo "$line"|sed "s%/me %%"`
   echo "<p><b><font size=-3>$date</font> * $nick $line</b>"
  else
   echo "<p><font size=-3><b>$date</b></font> &lt;$nick&gt; $line"
  fi
 done | sed "s%href=\"/%href=\"http://www.everything2.com/%g"
}


while true;do 


 $GET "$URL" > $TMPFILE
 #check for Word Galaxy
 if grep "<h3>Nate's Word Galaxy Generator</h3>" $TMPFILE >/dev/null;then
  # Every night, the Everything database is archived and ...
  sleep `expr $INTERVAL \* 4`
  continue
 fi

 # clean headerish stuff, compact to one msg per line, & feed into parsemsg()
 cat $TMPFILE          |
  sed "/CHATTER/d"     |
  sed "/^$/d"          |
  lam - -              |
  parsemsg > $TMPFILE2

 tail -100 $LOGFILE    |
  diff - $TMPFILE2     |
  grep "^> "           |
  cut -c3-             |
  tee -a $LOGFILE      |
  sed "{
s%<a [^>]*>%_%g
s%</a>%_%g
s%<[^>]*>%%g
s%&lt;%<%
s%&gt;%>%
s%&amp;%\&%
}"

 sleep $INTERVAL

done

Log in or register to write something here or to contact authors.