[LON-CAPA-cvs] cvs: modules /gerd classify.pl

www lon-capa-cvs@mail.lon-capa.org
Tue, 21 Mar 2006 22:00:54 -0000


www		Tue Mar 21 17:00:54 2006 EDT

  Added files:                 
    /modules/gerd	classify.pl 
  Log:
  Discussion classification script
  
  

Index: modules/gerd/classify.pl
+++ modules/gerd/classify.pl
use GDBM_File;
use File::Copy;
tie(%hash, 'GDBM_File', "msu_240017551b042fcpnetl1.db", &GDBM_READER(),0640);
tie(%already, 'GDBM_File','classified.db',&GDBM_WRCREAT(),0640);
open(OUT,">>classified.csv");
foreach $key (keys %hash) {
   if ($already{$key}) { next; }
   ($version,$item,$url)=split(/\:/,$key);
   if ($item eq 'keys') {
      if ($already{$key}) { next; }
      print "\n======\n";
      $sender=$hash{$version.':'.$url.':sendername'};
      $domain=$hash{$version.':'.$url.':senderdomain'};
      $message=$hash{$version.':'.$url.':message'};
      print &unescape($message)."\n>";
      $input=<STDIN>;
      chomp($input);
      if ($input eq 'q') {
         untie(%hash);
         untie(%already);
         close(OUT);
         $time=time;
         copy('classified.db','classified.'.$time.'.db');
         copy('classified.csv','classified.'.$time.'.csv');
         exit;
      }
      if ($input=~/^(\d[a-d])+$/) {
         print OUT "$sender,$domain,$url,$input\n";
         $already{$key}=1;  
      }
   }
}
untie(%hash);
untie(%already);
close(OUT);
exit;

# ----------------------------------------------------- Un-Escape Special Chars
    
sub unescape {
    my $str=shift;
    $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
    return $str;
}