Re: code |
Sun, 08 February 2004 15:40 |
|
hmm, after two levels error:
-
Attachment: diff.txt
(Size: 0.49KB, Downloaded 835 times)
|
|
Re: code |
Sun, 08 February 2004 15:38 |
|
AzaToth wrote on Sun, 08 February 2004 16:36 |
#!/usr/bin/perl -w
use HTML::TokeParser;
use HTML::Entities;
use Date::Manip;
use Tree::BPTree;
our %tag =
(
date => '',
name => '',
text => ''
);
my $tree = new Tree::BPTree();
my $olddate='';
our ($hubname,$date,$time,$trigger);
foreach(@ARGV)
{
($hubname,$date,$time) = $_ =~ /_(.*)_(\d{8})-(\d{6})/;
if($date)
{
$date = ParseDate("$date-$time");
&parse($_);
}
}
&write;
&write_to_disc;
sub write_to_disc
{
print "$trigger\n";
return unless $trigger;
open (NOUT, "> done/trantor-".UnixDate($olddate,'%Q').".xml");
print NOUT "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\"cl.xsl\"?>\n<hub name=\"Trantor\">\n";
while(my ($key,$value) =$tree->each)
{
print NOUT $value;
}
print NOUT "</hub>";
close NOUT;
$tree->clear;
$trigger = 0;
}
sub parse
{
$file = $_;
$p = HTML::TokeParser->new($file);
while( my $token = $p->get_token)
{
$data = $p->get_text;
if($data =~ /\[\d{2}:\d{2}:\d{2}\]/)
{
$data =~ s/\[(.*?)\]/$1/;
&write_to_disc if $olddate ne '' and $trigger and (UnixDate($date,'%Q') != UnixDate($olddate,'%Q'));
$olddate = $date;
$date = Date_GetNext($date,undef,1,$data);
&write($date);
}
}
}
sub write
{
$data = $_[0];
do{$tree->insert($tag{date}," <message author=\"$tag{name}\" date=\"$tag{date}\">\n $tag{text}\n </message>\n"); $trigger++} unless $tag{name} =~ /(DCGUI|Hub-Security|Command|mini-madwax|Hub)/ or $tag{name} eq '';
$tag{date} = $data;
$p->get_tag("b");
($tag{name} = encode_entities($p->get_text("/b"), '<>&"')) =~ s/\r/\n/g;
$tag{name} =~ s/(^<|>$)//g;
$p->get_tag("font");
($tag{text} = encode_entities($p->get_text("/font"), '<>&"')) =~ s/\r/\n/g;
$tag{text} =~ s/\n/<br\/>/g;
$tag{text} =~ s/(|)/?/g;
}
|
again
|
|
code |
Sun, 08 February 2004 15:36 |
|
#!/usr/bin/perl -w
use HTML::TokeParser;
use HTML::Entities;
use Date::Manip;
use Tree::BPTree;
our %tag =
(
date => '',
name => '',
text => ''
);
my $tree = new Tree::BPTree();
my $olddate='';
our ($hubname,$date,$time,$trigger);
foreach(@ARGV)
{
($hubname,$date,$time) = $_ =~ /_(.*)_(\d{8})-(\d{6})/;
if($date)
{
$date = ParseDate("$date-$time");
&parse($_);
}
}
&write;
&write_to_disc;
sub write_to_disc
{
print "$trigger\n";
return unless $trigger;
open (NOUT, "> done/trantor-".UnixDate($olddate,'%Q').".xml");
print NOUT "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\"cl.xsl\"?>\n<hub name=\"Trantor\">\n";
while(my ($key,$value) =$tree->each)
{
print NOUT $value;
}
print NOUT "</hub>";
close NOUT;
$tree->clear;
$trigger = 0;
}
sub parse
{
$file = $_;
$p = HTML::TokeParser->new($file);
while( my $token = $p->get_token)
{
$data = $p->get_text;
if($data =~ /\[\d{2}:\d{2}:\d{2}\]/)
{
$data =~ s/\[(.*?)\]/$1/;
&write_to_disc if $olddate ne '' and $trigger and (UnixDate($date,'%Q') != UnixDate($olddate,'%Q'));
$olddate = $date;
$date = Date_GetNext($date,undef,1,$data);
&write($date);
}
}
}
sub write
{
$data = $_[0];
do{$tree->insert($tag{date}," <message author=\"$tag{name}\" date=\"$tag{date}\">\n $tag{text}\n </message>\n"); $trigger++} unless $tag{name} =~ /(DCGUI|Hub-Security|Command|mini-madwax|Hub)/ or $tag{name} eq '';
$tag{date} = $data;
$p->get_tag("b");
($tag{name} = encode_entities($p->get_text("/b"), '<>&"')) =~ s/\r/\n/g;
$tag{name} =~ s/(^<|>$)//g;
$p->get_tag("font");
($tag{text} = encode_entities($p->get_text("/font"), '<>&"')) =~ s/\r/\n/g;
$tag{text} =~ s/\n/<br\/>/g;
$tag{text} =~ s/(|)/?/g;
}
|
|