#!/usr/bin/perl use CGI qw(:standard); use LWP::Simple qw/get/; use HTML::Parser; use HTML::Element; use URI::URL; # output a document @num = (); $countCols = 0; $incr = 'false'; $countTD = 0; $config = $ARGV[0]; do "/home/daz/downloads/palm/bussched/buses/$config.txt"; @headings = @MON_FRI_HEAD; @numIncrRows = @MON_FRI_INCR; $get_address = $MON_FRI_URL; #$extraDay = $EXTRA; $numIncrRowsSection = 0; my $content = get($get_address); #put site html in $content. #die "get failed" if (!defined $content); # create parser object my $parser = HTML::Parser->new(api_version=>3, start_h=>[\&startTag, 'tag, attr'] , end_h=>[\&endTag, 'tag'] , text_h=>[\&textElem, 'text'] ); #parse object. $parser->parse($content); sub startTag { my ($tag, $attrHash) = @_; if ($tag =~ 'th') { $count++; } if ($tag =~ 'td') { $heading = @headings[$countTD]; $countTD++; } if ($tag =~ 'colgroup') { $cols = $count - 1; # print 'number cols=' . $cols; } if ($tag =~ 'tr') { $lastTestTime = 60; $testTime1 = $time1; #print "\n"; } } sub endTag { my $tag = shift; print $text; if ($tag =~ "/td") { if ($incr eq "true") { } else { print ","; } } if ($tag =~ "/tr") { $countTD = 0; } } sub textElem { my $text = shift; my $tag = shift; $text =~ s/://; ($test) = $text =~ m/.*(Then at these minutes past the hour between) . */; if ($test =~ "Then at these minutes past the hour between") { $numIncrRows = @numIncrRows[$numIncrRowsSection]; $numIncrRowsSection++; $tempRow = 0; $boo = 0; $countCols = 0; @num = ''; $incr = 'true'; ($time1) = $text =~ m{([0-9]{1,2}[: ]?[0-9]{2})}; $text =~ s/$time1//; ($time2) = $text =~ m{([0-9]{1,2}[: ]?[0-9]{2})}; $testTime1 = $time1; # print "TIMEEEEE=" . $testTime1 . "TIME2=" . $time2 . "\n"; $time2 =~ s/://; #print 'time1='.$time1."time2=" . $time2 ."\n"; #die; } ($test2) = $text =~ m/.*(From) . */; if ($test2 =~ "From") { $incr = 'false'; } if ($incr=~'true') { #print "ACTUAL TEXT=" . $text . " "; if (!$text eq "") { ($testWords) = $text =~ m/^([0-9])/; #print "testWords = " . $testWords . "\n"; ($testNoTime) = $text =~ m/-/; if (($testWords =~ /^-?\d/) || ($testNoTime) ) { if ($text =~ "-") { $textComp = 0; } else { $textComp = $text; } $tempTime = $testTime1; $testTime = 60 - $textComp; if ($testTime > $lastTestTime) { if ($text =~ "-") { $testTime1 = $testTime1; } else { $testTime1 = $testTime1 + 100; } } $lastTestTime = $testTime; if ($text =~ "-") { $text = "xxx"; } else { $text = $text + $testTime1; } push (@num, $text); # print "text=" . $text . " count=" . $countCols . " COLS=". $cols . " >>> "; } if ($countCols == $cols) { # print "array="; # print @num; $tempRow++; $countCols = 0; if ($tempRow == $numIncrRows ) { for ($arrayTime=1; $arrayTime <= $numIncrRows; $arrayTime++) { # print "COLUMNS!!!!!!!!!!!!!! = " . $cols; $start = (($cols * $arrayTime) - $cols) + 1; $finish = ($cols * $arrayTime); #print "start = " . $start; #print "finish = " . $finish; $arrayNameIs = "slicenum" . $arrayTime; @$arrayNameIs = @num[$start..$finish]; } $numOfIncr = ((($time2 - $time1) / 100)-1); #print "num of incr = " . $numOfIncr; # print "array1="; # print @slicenum1[0..10]; # print "array2="; # print @slicenum2[11..20]; for ($arrayTime=1; $arrayTime <= $numIncrRows; $arrayTime++) { for ($blah=0; $blah < $cols; $blah++) { $arrayNameIs = "slicenum" . $arrayTime; if (@$arrayNameIs[$blah] =~ 'xxx') { print "@$arrayNameIs[$blah]" . ","; } else { print "@$arrayNameIs[$blah]" . @headings[$blah] . ","; } } } #die; for ($sex=0; $sex < $numOfIncr; $sex++) { $boo = $boo + 100; for ($arrayTime=1; $arrayTime <= $numIncrRows; $arrayTime++) { for ($blah=0; $blah < $cols; $blah++) { $arrayNameIs = "slicenum" . $arrayTime; if (@$arrayNameIs[$blah] =~ 'xxx') { print "@$arrayNameIs[$blah]" . ","; } else { print "@$arrayNameIs[$blah]" + $boo . @headings[$blah] . $extraDay . ","; } } } } } } $countCols++; } } ($testText) = $text =~ m/^([A-Z]|[a-z])/; if (!$testText) { if ($incr=~'false') { if (($text eq "-") || ($text eq "xxx")) { print $text; } else { print $text . $heading . $extraDay; } } } } print end_html();