#!/usr/bin/perl
##################################################
# mara -- Mike Schilli, 2001 (m@perlmeister.com)
##################################################
use warnings;
use strict;

use lib '/home/mike/perl';
use HTML::TableExtract;
use LWP::Simple ();
use Date::Calc qw(Today Add_Delta_DHMS);
use CGI qw(:all *table *TR);
use CGI::Carp qw(fatalsToBrowser);

my $URL = 
   "http://www.chroniclemarathon.com/course.html";
my @START_TIME = (7,0,0);  # 7:00 geht's los
my @SPEEDS     = (7.5, 7.0, 6.5, 6.0, 5.5, 5);

my $data = LWP::Simple::get($URL) or
    die "Fetching $URL failed";

my $te = new HTML::TableExtract(
          headers => [qw(Direction Street Mile)]);
$te->parse($data);

print header(), start_html();
print start_table({border => 1});
print th(["Where", "Mile", @SPEEDS]);

    # Reihen der ersten passenden Tabelle
ROW: foreach my $row ($te->rows) {

    print start_TR();

    foreach my $col (@$row) {
        next ROW if $col =~ /^\s*$/s;
    }
         
    print td("$row->[0] $row->[1]"),
          td($row->[2]);

    foreach my $speed (@SPEEDS) {
        my $secs = $row->[2] / $speed * 3600;
        my $time = sprintf "%02d:%02d", 
              (Add_Delta_DHMS(Today(),@START_TIME,
                               0,0,0,$secs))[3,4];
        print td($time);
    }
    print end_TR();
}

print end_table(), end_html();
