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;
}