Hi all,

I have gotten a pretty complete shot at what I needed for a TV guide that I could pluck. First, you have to download xmltv from sourceforge. Next, you have to go through the configuration for xmltv for your location and broadcast and then retrieve the listings. The next step is to run the Perl program at the end of this letter. The perl program creates a directory, "html" in the directory from which it is run (yeah, I know, ugly). Within this are thousands of files and about seven other directories. You pluck html/guide.html and plucker will handle the rest. The result is about 160K of data giving you the listings for your stations and descriptions about what is on. Right now, the script below pulls all seven days that xmltv retrieves, so if you want to use less space you can reduce the pull to only one day or something like that.

The result:

The first page has the days listed. Select a day.

This page has the channel for your show and then the title of the show. If the show is underlined (a link), then the show has a description.

Click on show links to get to a description.

Thus, you have to set the depth on plucker to 3 and I went ahead and set it to 4 'cause I'm honery.

This works for now and when the next rev of plucker is out of beta and tables are supported, I'll probably write something to put into tables.

Thanks for everyone's suggestions and ideas, but I ended up growing this from the ground up, so all the errors in logic or code are mine. Do what you want with the script.

William Fishburne

-- start script --

use Data::Dumper;
use File::Path;
require XML::Simple;

my $xs = new XML::Simple(keyattr => { channel => id }, suppressempty => 1 );
my $ref = $xs->XMLin("./guide.xml");

#print Dumper($ref);
#exit;

my $channels={};

foreach my $chan (keys (%{$ref->{'channel'}})) {
 $channels->{$chan} = substr $ref->{'channel'}->{$chan}->{'display-name'},8;
}

# Debug to be sure that the channels are coming in properly
#foreach my $chan (keys (%{$channels})) {
#  print $channels->{$chan}."\n";
#}

# Build a breakdown on the half-hour, for each day.
my $programs={};

for (my $prog_cnt=0; $prog_cnt <= $#{$ref->{'programme'}}; $prog_cnt++) {
 my $day = substr $ref->{'programme'}->[$prog_cnt]->{'start'}, 0, 8;
 my $start_time = substr $ref->{'programme'}->[$prog_cnt]->{'start'}, 8, 4;
 my $channel = $channels->{$ref->{'programme'}->[$prog_cnt]->{'channel'}};
 $programs->{$day}->{$start_time}->{$channel}->{'stop'} = substr 
$ref->{'programme'}->[$prog_cnt]->{'stop'}, 8, 4;
 $programs->{$day}->{$start_time}->{$channel}->{'desc'} = 
$ref->{'programme'}->[$prog_cnt]->{'desc'};
 $programs->{$day}->{$start_time}->{$channel}->{'title'} = 
$ref->{'programme'}->[$prog_cnt]->{'title'};
}

# Debug to be sure that the programs are coming in properly
#print Dumper($programs);
#exit;

rmtree("html");
mkpath("html");
chdir("html");
open HEADFILE, ">guide.html" or die "Unable to open guide.html";
print HEADFILE "<html><body>\n<h1>TV Guide</h1>\n";
foreach my $day (sort keys (%{$programs})) {
 my $month = substr $day, 4, 2;
 my $m_day = substr $day, 6, 2;
 my $l_month = ('January', 'February', 'March', 'April', 'May', 'June', 'July', 
'August', 'September', 'October', 'November', 'December')[$month-1];
 my $l_date = $l_month." ".($m_day+0).", ".substr($day,0,4);
 my $subdir = substr($day,0,8);
 my $detail_cnt = 0;
 print HEADFILE "<p><a href=\"".$subdir."/day_list.html\">".$l_date."</a></p>\n";
 mkpath($subdir);
 chdir($subdir);
 open DAYFILE, ">day_list.html" or die "Unable to open ".$subdir."/day_list.html";
 print DAYFILE "<html><body>\n";
 print DAYFILE "<h1>".$l_date."</h1>\n";
 my $last_hour = "";
 foreach my $hour (sort hoursort keys (%{$programs->{$day}})) {
   if ($last_hour ne $hour) {
     my $am_pm = $hour > 1159 ? "PM" : "AM";
     my $clock_time = $hour > 1159 ? (substr($hour,0,2)-12).":".substr($hour,2,2) : 
substr($hour,0,2).":".substr($hour,0,2);
     print DAYFILE "<h2>".$clock_time." ".$am_pm."</h2>\n";
   }
   $last_hour = $hour;
   foreach my $chan (sort chansort keys (%{$programs->{$day}->{$hour}})) {
     my $title = $programs->{$day}->{$hour}->{$chan}->{'title'};
     if (defined $programs->{$day}->{$hour}->{$chan}->{'desc'}) {
       open DETAIL, ">".$hour.$detail_cnt.".html" or die "Unable to open 
".$subdir."/".$hour.$detail.cnt.".html";
       print DAYFILE "<p>".$chan." <a 
href=\"".$hour.$detail_cnt.".html\">".$title."</a></p>\n";
       $detail_cnt++;
       print DETAIL "<html><body>\n";
       print DETAIL "<h1>".$title."</h1>\n";
       print DETAIL 
"<p>".$programs->{$day}->{$hour}->{$chan}->{'desc'}."</p>\n</body></html>";
       close DETAIL;
     } else {
       print DAYFILE "<p>".$chan." ".$title."</p>\n";
     }
   }
 }
 print DAYFILE "</body></html>\n";
 close DAYFILE;
 chdir("..");
}
print HEADFILE "</body></html>\n";
close HEADFILE;

sub chansort { (substr($a,0,2)+0) <=> (substr($b,0,2)+0); }
sub hoursort { ($a < 600 ? $a + 2400 : $a) <=> ($b < 600 ? $b + 2400 : $b); }


_______________________________________________ plucker-list mailing list [EMAIL PROTECTED] http://lists.rubberchicken.org/mailman/listinfo/plucker-list

Reply via email to