FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » General » Test Forum » code
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
code [message #16576] Sun, 08 February 2004 15:36 Go to next message
AzaToth is currently offline  AzaToth   Sweden
Messages: 125
Registered: October 2003
Karma: 0
Senior Member

#!/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/(^&lt;|&gt;$)//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;
}
Re: code [message #16577 is a reply to message #16576] Sun, 08 February 2004 15:38 Go to previous messageGo to next message
AzaToth is currently offline  AzaToth   Sweden
Messages: 125
Registered: October 2003
Karma: 0
Senior Member

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
Re: code [message #16578 is a reply to message #16576] Sun, 08 February 2004 15:40 Go to previous message
AzaToth is currently offline  AzaToth   Sweden
Messages: 125
Registered: October 2003
Karma: 0
Senior Member

hmm, after two levels error:
  • Attachment: diff.txt
    (Size: 0.49KB, Downloaded 835 times)

[Updated on: Sun, 08 February 2004 15:41]

Report message to a moderator

  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: test
Next Topic: ssssssssss
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 11:51:38 GMT 2024

Total time taken to generate the page: 0.01909 seconds