Removing uneeded file.
[and.git] / PC^2 / pc2 / samps / rotate_summary
blob60fe963fb941ca1e01d0e998cd3513e124a5aadd
1 #!/usr/bin/perl
2 #
3 # File: rotate_summary
4 # Purpose: to create rotating html web pages based on summary.html
5 # Author: pc2@ecs.csus.edu
6 # Revised: Sun May 1 13:09:03 PDT 2005
7 #
8 # $Id: rotate_summary,v 1.2 2006/04/12 15:35:59 boudreat Exp $
9 #
12 # Input
14 # summary.html in current directory.
16 # Ouptut
18 # Creates a number of new summary html files in current directory
19 # named in the form of summary#.html where summary1.html is the first
20 # file created.
22 # Directions:
24 # CUSTOMIZE HERE
25 $perpage=14; # number of teams per page
27 # set this to 1, run script once at cutoff time
28 $nomoreupdates=0;
29 $cutofftime="1 hour";
31 # REFRESH value
32 $refresh=15;
34 # the number of attempts we try to read the html file
35 $maxretry=4;
37 # set to "" not print a banner
38 $banner="../banner.png";
39 # END CUSTOMIZATION
42 $f="summary.html";
43 $done=0;
44 $rowcount=0;
45 for($retry=0;(($retry < $maxretry ) && $done == 0); $retry++) {
46 open(IN,"$f") || die("Unable to read $f: $!\n");
47 while(<IN>) {
48 chomp;
49 if (/\<tr\>/) {
50 if ($firstrow eq "") {
51 s/tr/tr BGCOLOR="#EEEEFF"/ if $rowcount % 2 == 0;
52 $firstrow=$_;
53 } elsif (/\<td\>\<\/td\>/i) { # color line
54 s/tr/tr BGCOLOR="#EEEEFF"/ if $rowcount % 2 == 0;
55 $firstrow .= $_;
56 } elsif (/\<td\>Submitted/i) {
57 $summary=$_;
58 $summary =~ s@tr@tr><td>&nbsp;</td></tr><tr BGCOLOR="#EEEEFF"@;
59 $summary =~ s#<td>(\d+/(--|\d+)(/\d+)?)</td>#<td align=center>$1</td>#g;
60 } elsif (/\<td cellwid?th/i) { # v8.7-1115 has this misspelled
61 next; # blank line before summary
62 } elsif (/\<tr\>/) {
63 $rowcount++;
64 s/tr/tr BGCOLOR="#EEEEFF"/ if $rowcount % 2 == 0;
65 s#<td>(\d+/(--|\d+))</td>#<td align=center>$1</td>#g;
66 s#<td>(\d+)</td><td>(\d+)</td>#<td align="center">$1</td><td align="right">$2</td>#g;
67 s#<td>(\c+)</td>#<td align=right>$1&nbsp;&nbsp;</td>#g;
68 push(@rows,$_);
70 } elsif (/^Created by/i) {
71 $created="Created by California State University, Sacramento PC<sup>2</sup><br>\nhttp://www.ecs.csus.edu/pc2/<br>\n";
72 $_ = <IN>; # url line
73 $created.= <IN>; # Last Updated
74 $created.= <IN>; # Date
76 $done=1 if (/\<\/html\>/);
77 } # while <IN>
78 close(IN);
79 sleep 1 if ($done == 0);
81 if ($done == 0) {
82 die("Unable to read a complete $f\n");
85 @nextpage=&gen_page_seq($#rows, $perpage);
86 # page sequence already contains padding 1st value
87 $maxpage=$#nextpage;
89 foreach($page=1;$page <= $maxpage; $page++) {
90 &print_page($page,$nextpage[$page],($page-1)*$perpage+1,$page*$perpage);
93 sub gen_page_seq {
94 my($rowcount, $rows_per_page)=@_;
95 my(@result)=(-1); # 1st value is ignored
96 my($pages)=int($rowcount/$rows_per_page);
97 if ($pages * $rows_per_page != $rowcount) {
98 # we have a non-full page
99 $pages++;
101 # push a dummy value, so we can do $page[thispage] to get the next page
102 push(@pages,-1);
103 foreach($p=2; $p <= $pages ; $p++) {
104 push(@pages, $p);
106 push(@pages,1); # and back to the 1st page
107 return @pages;
110 sub print_page {
111 my($thispage,$nextpage,$start,$end)=@_;
112 # warn("print_page($thispage,$nextpage,$start,$end)\n");
114 open(OUT,">summary$thispage.html")
115 || warn("Unable to write summary$thispage.html");
116 $nextfile="summary$nextpage.html";
117 print OUT <<EOM;
118 <html>
119 <!-- next page is summary$nextpage.html -->
120 <META HTTP-EQUIV="REFRESH" CONTENT="$refresh; URL=$nextfile">
121 <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="no-cache">
122 <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
123 <head>
124 <title>
125 $start thru $end
126 </title>
127 </head>
128 <body>
129 <center>
131 if ($banner ne "" && -f $banner) {
132 print OUT <<EOM;
133 <IMG SRC="$banner" align="center">
136 print OUT <<EOM;
137 <table border=0 cellpadding=2>
138 $firstrow
140 $end=$#rows+1 if $end > ($#rows+1);
141 foreach($i=$start ; $i <= $end; $i++) {
142 print OUT $rows[$i-1]."\n";
144 print OUT <<EOM;
145 $summary
146 </table>
147 </center>
148 <font size=-1 face="verdana, arial, helvetica">
149 <p align=right>Page $page of $maxpage</p>
151 if ($nomoreupdates==1) {
152 # print OUT "<p align=center><font size=+2><b>No More Updates</b></font></p>";
153 print OUT "<p align=center><font size=+1><b>Standings with $cutofftime left. There will be no more scoreboard updates.</b></font></p>";
154 } else {
155 print OUT "<br><br>";
157 print OUT <<EOM;
158 $created</font>
159 </body>
160 </html>