#!perl -w
#####################################
##    pluck.pl
##    prepares a plucker DB home page from tvlistings.pl results
##    ready for plucker to convert and sync.
##
use strict;
use File::Find;
use File::Basename;
use CGI::Pretty  ':standard';

#select((select(STDOUT),$|=1)[0]); #<-- make STDOUT a hot handle.
#select((select(STDERR),$|=1)[0]); #<-- make STDERR a hot handle.

my $pluck = 'C:\Program Files\Plucker\plucker-build.exe';
#my $rootdir = 'D:/msemtd/Perl/tvlisting/run/pages';
my $rootdir = 'E:\Mick\perl\tvlistings\run\pages';
my $homefile = 'C:\Program Files\Plucker\TV.DB\home.html';

## make the home.html file...

open( HOME, ">$homefile") or die "can't open output file '$homefile': $!";
print HOME start_html('TV Listings');
print HOME h1('TV Listings');
find(\&ExamineFile, ($rootdir));
print HOME end_html;

sub ExamineFile
{
   return unless -f;
   return unless /\.(html|htm)$/i;
   my $file = $File::Find::name;
   print "Found: '$file'.\n";
   if(!open( PAGE, "<$file" )){
      warn "can't open page '$file' for read: $!";
      next;
   }
   ## Slurp the file...
   my $html;
   {
      local $/;
      undef $/;
      $html = <PAGE>;
   }
   ## Pull the title with simplistic regex...
   my ($title) = ($html =~ m#<TITLE>\s*(.*?)\s*</TITLE>#is);
   print "the title is '$title'\n";

   $file =~ tr/\\/\//;
   $file =~ tr/:/\|/;

   print HOME a({href=>"file:///$file"},"$title"), br, "\n";
}
__END__




" --db-file=tv --pluckerhome=pages