Everything2
Near Matches
Ignore Exact
Full Text
Everything2

Perl E2 chatterbox XML ticker parser

created by eric+

(thing) by eric+ (5.6 y) (print)   ?   (I like it!) Wed Jun 28 2000 at 19:47:03

A simple perl module to parse E2's chatterbox XML ticker. It's used with the XML::Parser module. POD (with a short example) is at the bottom. It converts the href's to square brackets, just like the nodelet. If you use it, remember to escape the '&' in the chatterbox XML ticker output, otherwise it dies, saying that the xml is not well-formed.

There's also a Perl E2 private message XML ticker parser.

package E2Chatterbox::ChatterParser;

use strict;

########################################################################
########################################################################
###
### XML subs
###
########################################################################
########################################################################
sub Init {
  my $expat = shift();

  $expat->{speaker} = undef;
  $expat->{message} = undef;
  $expat->{chatter} = [];
  $expat->{time} = undef;
  $expat->{room} = undef;
}


sub Char {
  my ( $expat, $string ) = @_;

  if ( defined($expat->{speaker}) ) {
    $string =~ s/\n//g;

    $expat->{message} .= $string;
  }
}

sub Start {
  my ( $expat, $element, %attr ) = @_;
  $element = lc( $element );

  if ( $element eq 'message' ) {
    $expat->{speaker} = $attr{author};
    $expat->{time}    = $attr{time};
  }
  elsif ( $element eq 'a' ) {
    $expat->{message} .= '[';
  }
  elsif ( $element eq 'info' ) {
    $expat->{room} = $attr{room};
  }
}

sub End {
  my ( $expat, $element ) = @_;
  $element = lc( $element );

  if ( $element eq 'message' ) {
    if ( $expat->{time} > $expat->{last_time} ) {
      push( @{$expat->{chatter}},
        [ $expat->{time}, $expat->{speaker}, $expat->{message} ] );
      $expat->{last_time} = $expat->{time};
    }

    $expat->{speaker} = undef;
    $expat->{message} = undef;
    $expat->{time} = undef;
  }
  elsif ( $element eq 'a' ) {
    $expat->{message} .= ']';
  }
}

sub Final {
  my $expat = shift();

  return ( $expat->{chatter}, $expat->{last_time} );
}


1;

=pod

=head1 NAME

E2ChatterboxCParser - XML parser for chatterbox XML ticker

=head1 SYNOPSIS

 use XML::Parser;

 my $parser = new XML::Parser( 
   Style => "E2Chatterbox::ChatterParser" 
  );

 my ($chatter_log, $last_time) = $parser->parse( $xml, 'last_time' => $time );

 foreach my $line ( @$chatter_log ) {
   my ( $time, $speaker, $speech ) = @$line;
   print "[$time] $speaker: $speech\n";
 }

=head1 DESCRIPTION

This is a style for the XML::Parser perl module that deals
with E2's xml chatterbox ticker (/?node=chatterbox+XML+ticker).
It requires two arguments (the xml from the ticker and the
time to start reading), and returns two values (a reference
to an array of arrays and the time of the last message read.)

=cut

(idea) by Shanoyu (2 y) (print)   ?   (I like it!) Sat Oct 28 2000 at 4:19:41

Unfortunately, now that I have all of the modules, it still doesn't work. Here are the errors I print out:

[Shan@ragu] (~)$ ./e2chatterbox.pl shanoyu *CENSORED*
Subroutine Init redefined at E2ChatterboxCParser.pm line 72.
Subroutine Char redefined at E2ChatterboxCParser.pm line 83.
Subroutine Start redefined at E2ChatterboxCParser.pm line 93.
Bareword "sage" not allowed while "strict subs" in use at E2ChatterboxCParser.pm line 137.
Unquoted string "sage" may clash with future reserved word at E2ChatterboxCParser.pm line 137.
"use" not allowed in expression at E2ChatterboxCParser.pm line 63, at end of line
syntax error at E2ChatterboxCParser.pm line 63, near "use strict"
syntax error at E2ChatterboxCParser.pm line 137, near "} ="
syntax error at E2ChatterboxCParser.pm line 140, near "elsif"
BEGIN failed--compilation aborted at E2Chatterbox2.pm line 14.
BEGIN failed--compilation aborted at ./e2chatterbox.pl line 5.


...elsif?

printable version
chaos

Perl E2 private message XML ticker parser Small helpful scripts for noders perl chatterbox client module E2 Explorer
E2 Link and Logger Client PHP E2 chatterbox XML ticker parser Why the chatterbox is not IRC XML parser
EDEV: Quick Confirmation XML clientdev: new XML ticker output mIRC E2 chatterbox XML ticker parser
Angry Young Man Intro to Nodetypes E2 Chatterbox Archive Pod
Words of Advice for Young People ASP E2 random nodes XML ticker Everything2 Hubs E2 Mozilla Chatterbox Client
bookbinding Chatterbox Maund hand in hand
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
The best nodes of all time:
The Hours
Henley by-election
The Sleeping Gypsy
Scottish Court rules: "Fuck off" is not an insult
Stupid Word Tricks
lime
Love is tangerine light
Nintendo DS
Saint Philomena
Harry Potter and the Half-Blood Prince
polyandry
My regret sits on the floor like someone else's polaroid photos
Clinical depression
New Writeups
TheOrientalAfrican
ToTheGuyWithAidsSittingN... (I Am Really Really Sorry)(person)
Heitah
Why I love Everything2(person)
trixingee
Dungeon Mastering for the first time(idea)
Netrat0
It's Called Subtext, Honey(person)
eyeofthebeholder
The Dragon(idea)
Heitah
consist, comprise, constitute, or compose(idea)
Meezzio
Gotlandssnus(thing)
argv
Astral Plane(idea)
Madara
One Winged Angel(fiction)
Tom Rook
Talk is cheap(poetry)
shaogo
Adelle Davis(person)
Aerobe
race car g sfjsgsd(poetry)
Binah
Dream Log: July 5, 2008(dream)
StrawberryFrog
Forgotten things in space(idea)
antigravpussy
velvet revolution fairy tale(idea)
Everything 2 is brought to you by the letter C and The Everything Development Company