sub core_parse {
my $html = HTML::TreeBuilder->new_from_file('Showtime.htm'); # openings files,
$html ? wlog("tree built") : wlog("tree error"); # building trees,
open(LISP, ">content.txt") or warn "Failed to open: $!\n"; # and logging. :) <-- pun?
my %showtime; wlog("looking for the content table");
my $table = $html->look_down('_tag', 'table', 'bgcolor', '#bfa89b', # gets the content table
sub { table_header_has($_[0], "ETA") },
sub { not table_header_has($_[0], "Starting") }
); wlog("table found. Starting parse");
foreach my $anime ($table->look_down('_tag', 'tr',
'align', undef, # <-- this line is for skipping-
'bgcolor', '#e9dfdb')){ # the first <tr> which isn't needed.
my $name = $anime->look_down('_tag', 'a', 'name', qr/\d+/)->parent(); # gets the name (for LINK stays as hash) [pc!]
my $link = $name->parent()->look_down('_tag', 'a', 'href', qr/anidb/); # get the <<RIGHT>> link (which is kinda good)
$showtime{$name->as_text}->{'link'} = $link ? anidb_short($link->{'href'}) : undef; # starts the hash->hash
$showtime{$name->as_text}->{'station'} = 3; # # # # # # # # #
$showtime{$name->as_text}->{'eta'} = 5; # better ideas? #
$showtime{$name->as_text}->{'airtime'} = 6; # # # # # # # # #
my @n_vals;
foreach my $node ($anime->look_down('_tag', 'td')) {
push(@n_vals,$node->as_text); # okay, so this is what I came up with
} foreach my $key (keys %{$showtime{$name->as_text}}) { # to replace the old hash -> hash
$showtime{$name->as_text}->{$key} = # I'm.. not sure if it's better or
$n_vals[$showtime{$name->as_text}->{$key}]; # worse xD oh well. thoughts?
}
}
wlog("storing values");
foreach my $key (sort keys %showtime) {
print LISP "$key -> @{[ map { $showtime{$key}->{$_} } @fields ]}\n";
}
wlog("work done, deleting tree");
$html->delete; close(LISP) or warn "Failed to close: $!\n";
print "All done....";
}