#!/usr/bin/perl # # File: rotate_summary # Purpose: to create rotating html web pages based on summary.html # Author: pc2@ecs.csus.edu # Revised: Sun May 1 13:09:03 PDT 2005 # # $Id$ # # # Input # # summary.html in current directory. # # Ouptut # # Creates a number of new summary html files in current directory # named in the form of summary#.html where summary1.html is the first # file created. # # Directions: # # CUSTOMIZE HERE $perpage=14; # number of teams per page # set this to 1, run script once at cutoff time $nomoreupdates=0; $cutofftime="1 hour"; # REFRESH value $refresh=15; # the number of attempts we try to read the html file $maxretry=4; # set to "" not print a banner $banner="../banner.png"; # change cell background color, set to 1 to enable # $wrong for attempted but incorrect submissions # $correct for successful submissions $show_colors=1; $wrong="#FF0000"; # red $correct="#00FF00"; # green $pending="#FFFF00"; # yellow # change 0/-- to   if set to 1 $blank_zero_submissions=1; # END CUSTOMIZATION $NBSP=q@ @; $f="summary.html"; $done=0; $rowcount=0; for($retry=0;(($retry < $maxretry ) && $done == 0); $retry++) { open(IN,"$f") || die("Unable to read $f: $!\n"); while() { chomp; if (/\/) { if ($firstrow eq "") { s/tr/tr BGCOLOR="#EEEEFF"/ if $rowcount % 2 == 0; $firstrow=$_; } elsif (/\\<\/td\>/i) { # color line s/tr/tr BGCOLOR="#EEEEFF"/ if $rowcount % 2 == 0; $firstrow .= $_; } elsif (/\Submitted/i) { $summary=$_; $summary =~ s@tr@tr>$NBSP(\d+/(--|\d+)(/\d+)?)#$1#g; } elsif (/\/) { $rowcount++; s/tr/tr BGCOLOR="#EEEEFF"/ if $rowcount % 2 == 0; if ($blank_zero_submissions == 1) { s#(0/--)#$1#; s@0/--@$NBSP@g; } if ($show_colors != 1) { s#(\d+/(--|\d+))#$1#g; } else { # leave summary column color alone s#(\d+/(--|\d+))#$1#; while(m#()?(\d+/(--|\d+))#) { if (m#(\d+/--)#) { s#(\d+/--)#$1#; } elsif (m#(\d+/--)#) { s#(\d+/--)#$1#; } elsif (m#(\d+/\d+)#) { s#()?(\d+/\d+)#$2#; } } } s#(\d+)(\d+)#$1$2#g; s#(\c+)#$1$NBSP$NBSP#g; push(@rows,$_); } } elsif (/^Created by/i) { $created="Created by California State University, Sacramento PC2
\nhttp://www.ecs.csus.edu/pc2/
\n"; $_ = ; # url line $created.= ; # Last Updated $created.= ; # Date } $done=1 if (/\<\/html\>/i); } # while close(IN); sleep 1 if ($done == 0); } if ($done == 0) { die("Unable to read a complete $f\n"); } @nextpage=&gen_page_seq($#rows, $perpage); # page sequence already contains padding 1st value $maxpage=$#nextpage; foreach($page=1;$page <= $maxpage; $page++) { &print_page($page,$nextpage[$page],($page-1)*$perpage+1,$page*$perpage); } sub gen_page_seq { my($rowcount, $rows_per_page)=@_; my(@result)=(-1); # 1st value is ignored my($pages)=int($rowcount/$rows_per_page); if ($pages * $rows_per_page != $rowcount) { # we have a non-full page $pages++; } # push a dummy value, so we can do $page[thispage] to get the next page push(@pages,-1); foreach($p=2; $p <= $pages ; $p++) { push(@pages, $p); } push(@pages,1); # and back to the 1st page return @pages; } sub print_page { my($thispage,$nextpage,$start,$end)=@_; # warn("print_page($thispage,$nextpage,$start,$end)\n"); open(OUT,">summary$thispage.html") || warn("Unable to write summary$thispage.html"); $nextfile="summary$nextpage.html"; print OUT < $start thru $end
EOM if ($banner ne "" && -f $banner) { print OUT < EOM } print OUT < $firstrow EOM $end=$#rows+1 if $end > ($#rows+1); foreach($i=$start ; $i <= $end; $i++) { print OUT $rows[$i-1]."\n"; } print OUT <

Page $page of $maxpage

EOM if ($nomoreupdates==1) { # print OUT "

No More Updates

"; print OUT "

Standings with $cutofftime left. There will be no more scoreboard updates.

"; } else { print OUT "

"; } print OUT < EOM }