Often during the day, I'll have PM running in a windows and I'll occasionally chat through the Chatterbox. Sometimes though, I'll get distracted or have to attend to work :) and I can miss some of the comments going on in the chatterbox.

So I decided I wanted something that would just show me the contents of the chatterbox - so I came up with this. It doesn't do any parsing of stuff between [ ... ] so you need to have an understanding of how stuff gets coded in the cb but other than that it seems to work pretty well.

As for not using XML::Parser, I thought about it but when I tried to install it using CPAN but the make fell over, so I went with some very coarse regexp stuff instead.

As always, comments on how this could be improved are welcome.
UPDATED: Changed sleep to 60 seconds - thanks to Kanji for pointing out original sleep was a bit low

#!/usr/bin/perl use strict; use warnings; use diagnostics; require LWP::UserAgent; sub check_xml; my $last = 0; for (;;) { $last = check_xml($last); sleep(60); } exit; sub check_xml() { my $last = shift; my $ua = LWP::UserAgent->new; # # OK, we need to grab this through a proxy since we're behind a firewa +ll # $ua->proxy('http', 'http://nn.nn.nn.nn:8088/'); # # So go and grab the page # my $request = HTTP::Request->new('GET', 'http://www.perlmonks.org/inde +x.pl?node=chatterbox%20xml%20ticker'); my $response = $ua->request($request); # # If it worked # my ($author, $time, $msg); if ($response->is_success) { { $/=''; $_ = $response->content; $_ = join ' ',m/^\<message (user_id.*?time=\"\d+\")(?:>\n)(.*? +)\<\/message\>(\n)/mgis; } foreach (split /\n/, $_) { ($author, $time, $msg) = m/author=\"(.*?)\" time=\"(\d+?)\" (. +*)/i; print "[$author]: $msg\n" if ($time > $last); } } return $time; }

Replies are listed 'Best First'.
Re: Quick & Dirty Chatterbox monitor
by Kanji (Parson) on Oct 18, 2002 at 18:10 UTC

    Perhaps it's just me, but hitting the CB ticker every 20 seconds just seems a little excessive, esp. when there are other scripts out there (like the excellent cblast35 and robomonk) that perform a very similar service.

        --k.


      Yes, I did think that which is why I've been playing with that sleep, and currently it's sat @ 60 seconds on my machine

      --
      But today you took me walking, Through a land that we have lost,
      While our children sit at websites, With no access to the cost

Re: Quick & Dirty Chatterbox monitor
by jdporter (Paladin) on Nov 18, 2002 at 20:47 UTC
    This is quite similar to one that I wrote. Like you, I used regex instead of parsing XML. The only additional things my version does are:
    1. manip the time so as to show the interval since the previous message; and
    2. save everything to a log file.

    The one bit of recommendation I'd make is that you don't need to re-instantiate the UserAgent object each time through the loop. One will do for the lifetime of the process. In fact, the same is true for the Request object as well.

    jdporter
    ...porque es dificil estar guapo y blanco.