Quick hack to improve vCal output
[tpope-extra.git] / perl / schedproc
1 #!/usr/bin/perl -w
2 # $Id$
3 # -*- perl -*- vim: ft=perl sw=4 sts=4
4
5 # Brief usage instructions:
6 # Create a ~/.schedprocrc that has schedule=/path/to/schedule.xml and
7 # grades=/path/to/grades.xml.  HTTP URLs are acceptable
8
9 use strict;
10 use Date::Calc::Object qw(Day_of_Week Decode_Day_of_Week Decode_Month Week_of_Year Monday_of_Week Day_of_Week_Abbreviation Delta_Days Add_Delta_Days Nth_Weekday_of_Month_Year Gmtime Mktime);
11 use Date::Calendar::Profiles qw($Profiles);
12 use Date::Calendar::Year;
13 use Getopt::Long;
14 use LWP::UserAgent;
15 use XML::Simple;
16 use vars qw(%opts %faculty %facurl);
17
18 $opts{'config'} = $ENV{HOME} . "/.schedprocrc";
19
20 my $arg = $ARGV[0] || "";
21 if($arg eq "-x") {
22     shift;
23     $opts{'format'} = "xml";
24 } elsif($arg eq "-h") {
25     shift;
26     $opts{'format'} = "html";
27 } elsif($arg eq "-m") {
28     shift;
29     $opts{'format'} = "mhc";
30 } elsif($arg eq "-c") {
31     shift;
32     $opts{'format'} = "csv";
33 } elsif($arg eq "-v") {
34     shift;
35     $opts{'format'} = "vcs";
36 } elsif($arg eq "-g") {
37     shift;
38     $opts{'format'} = "grades";
39 }
40
41 Getopt::Long::Configure ("bundling", "auto_help");
42 die "Invalid arguments\n" unless
43 GetOptions(\%opts, 'schedule|S=s', 'grades|G=s', 'faculty=s', 'name|n=s', 'format|f=s', 'config|F=s', 'out|o=s');
44
45 if (-r $opts{'config'}) {
46     open CONFIG, $opts{'config'} or die $!;
47     while(<CONFIG>) {
48         s/\#.*//;
49         next unless m/^([^=]*)=(.*)/;
50         my ($l, $r) = ($1, $2);
51         if ($l =~ /^(schedule|grades|name|faculty)$/) {
52             $opts{$l}||=$r;
53         } else {
54             warn "Unknown config file option $l.\n";
55         }
56     }
57     close CONFIG;
58 }
59
60 $opts{'schedule'} ||= "~/schedule.xml";
61 $opts{'grades'} ||= "~/grades.xml";
62 $opts{'faculty'} ||= "";
63
64 $opts{'schedule'} =~ s/(^|,)~\//$1$ENV{HOME}\//;
65 $opts{'grades'} =~ s/(^|,)~\//$1$ENV{HOME}\//;
66 $opts{'faculty'} =~ s/(^|,)~\//$1$ENV{HOME}\//;
67
68 if(!defined($opts{'out'}) && defined($ARGV[0])) {
69     $opts{'out'} = shift;
70 }
71
72 if(!defined($opts{'format'}) && defined($opts{'out'})) {
73     $opts{'format'} = $opts{'out'};
74     $opts{'format'} =~ s/.*\.//;
75     $opts{'format'} =~ s/^(.*\/|)\.?schedule$/mhc/;
76     undef $opts{'out'} if($opts{'out'} =~ /^(html|mhc|csv|vcs|xml|grades)$/);
77 }
78
79 $opts{'format'} ||= "";
80 undef $opts{'out'} if(($opts{'out'}||"") eq "-");
81
82 sub generate_id {
83     my ($section, $number) = split("-", shift);
84     my $id = 0;
85     foreach (split //, $section) {$id=26*$id+(ord($_)-1)%32;}
86     $id=10000*$id+$number;
87     return $id;
88 }
89
90 sub first_class {
91     my %class = @_;
92     $class{'duration'} =~ /(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)/;
93     my $days = Delta_Days($1,$2,$3,$4,$5,$6);
94     my $firstday = Date::Calc->new($1,$2,$3);
95     my $lastday = Date::Calc->new($4,$5,$6);
96     my $today;
97     my @days=();
98     foreach(split(" ",$class{'days'})) {
99         push @days, Decode_Day_of_Week($_);
100     }
101     my @off = ();
102     @off = @{$class{'off'}} if ($class{'off'});
103     for($today = $firstday; $today < $lastday; $today++) {
104         next unless(grep($_ == Day_of_Week($today->date), @days));
105         next if(grep($_ == "$today", @off));
106         return $today;
107     }
108     return undef;
109 }
110
111 sub next_class {
112     my %class = @_;
113     $class{'duration'} =~ /(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)/;
114     my $days = Delta_Days($1,$2,$3,$4,$5,$6);
115     my $firstday = Date::Calc->new($1,$2,$3);
116     my $lastday = Date::Calc->new($4,$5,$6);
117     my $today = Date::Calc->new(Date::Calc->localtime(time+3600*6)->date);
118     my @days=();
119     foreach(split(" ",$class{'days'})) {
120         push @days, Decode_Day_of_Week($_);
121     }
122     my @off = ();
123     @off = @{$class{'off'}} if ($class{'off'});
124     for($today = ($today > $firstday ? $today : $firstday); $today < $lastday; $today++) {
125         next unless(grep($_ == Day_of_Week($today->date), @days));
126         next if(grep($_ == "$today", @off));
127         return $today;
128     }
129     $today = Date::Calc->new(Date::Calc->gmtime->date);
130     for($today = ($today < $lastday ? $today : $lastday); $today > $firstday; $today--) {
131         next unless(grep($_ == Day_of_Week($today->date), @days));
132         next if(grep($_ == "$today", @off));
133         return $today;
134     }
135     return undef;
136 }
137
138 sub capitalize {
139     local $_ = shift || "";
140     s/ +$//;
141     s/\b([A-Z])([A-Z]*)\b/$1\L$2/g;
142     s/\b(I)(i*)\b/$1\U$2/g;
143     s/\bUs\b/US/g;
144     s/ (And|For|Of|Or|The|To|With) / \l$1 /g;
145     s/\b(Mc)([a-z])/$1\u$2/g;
146     s/\b(Tcp\/Ip|Pc|Tba)\b/\U$&/g;
147     s/\bThru\b/Through/g;
148     s/\bAcct\b/Accounting/g;
149     s/\bAmer\b/American/g;
150     s/\bChem\b/Chemistry/g;
151     s/\bComp\b/Composition/g;
152     s/\bFed\b/Federal/g;
153     s/\bGen\b/General/g;
154     s/\bIntro\b/Introduction/g;
155     s/\bPrgm\b/Programming/g;
156     s/\bOp Sys\b/Operating System/g;
157     #s/\bGovt\b/Government/g;
158     s/\bLit\b/Literature/g;
159     s/\bPrin\b/Principles/g;
160     s/\bBus\b/Business/g;
161     s/\bSyst\b/Sys/g;
162     return $_;
163 }
164
165 sub read_fileurl {
166     my $content;
167     my $url=shift;
168     if($url =~ /:\/\//) {
169         my $ua = LWP::UserAgent->new;
170         $ua->timeout(10);
171         $ua->env_proxy;
172 #       $ua->cookie_jar( {} );
173         my $response = $ua->get("$url") or die "$!";
174         die $response->status_line unless $response->is_success;
175         $content = $response->content;
176     } else {
177         open(F,$url) || die "$!";
178         $content = join ("", <F>);
179         close F;
180     }
181     return $content;
182     #my $ref = XMLin($content, ForceArray => [ 'class', 'cumulative', 'off' ], KeyAttr => "");
183     #return @{$ref->{'class'}};
184 }
185
186 sub get_schedule {
187     my $content = read_fileurl($opts{'schedule'});
188     my $ref = XMLin($content, ForceArray => [ 'class', 'off' ], KeyAttr => "");
189     die "Could not load schedule.\n" unless $ref->{'class'};
190     return @{$ref->{'class'}};
191 }
192
193 sub get_grades {
194     my $content = read_fileurl($opts{'grades'});
195     my $ref = XMLin($content, ForceArray => [ 'class', 'cumulative' ], KeyAttr => "");
196     return $ref;
197 }
198
199 sub load_faculty {
200     my ($name, $email, $url, $content);
201     if(($opts{'faculty'}) && ! %faculty) {
202         $content = read_fileurl($opts{'faculty'});
203         foreach $_ (split("\n", $content)) {
204             m/"([^"]*)",([^,]*),([^,]*)/; # "
205             ($name, $email, $url) = ($1, $2, $3);
206             next unless ($name);
207             $name =~ s/ [A-Z]\.//g;
208             $name = lc $name;
209             $name =~ s/\W//g;
210             $faculty{$name} = $email if($email);
211             $facurl{$name} = $url if ($url);
212         }
213     }
214 }
215
216 sub get_faculty_email {
217     load_faculty();
218     my ($name);
219     $name = shift;
220     $name =~ s/ [A-Z]r?\.//g;
221     $name = lc $name;
222     $name =~ s/\W//g;
223     return $faculty{$name};
224 }
225
226 sub get_faculty_url {
227     load_faculty();
228     my ($name);
229     $name = shift;
230     $name =~ s/ [A-Z]r?\.//g;
231     $name = lc $name;
232     $name =~ s/\W//g;
233     return $facurl{$name};
234 }
235
236 sub get_mhc_header {
237 return (
238 "X-SC-Subject: New Years Day\nX-SC-Category: Holiday\nX-SC-Cond: 1 Jan\nX-SC-Duration: 00010101-\nX-SC-Record-Id: <New_Years_Day\@from.sctweb>\n",
239 "X-SC-Subject: Martin Luther King, Jr. Day\nX-SC-Category: Holiday\nX-SC-Cond: 3rd Mon Jan\nX-SC-Duration: 19870119-\nX-SC-Record-Id: <Martin_Luther_King_Jr_Day\@from.sctweb>\n",
240 "X-SC-Subject: Presidents Day\nX-SC-Category: Holiday\nX-SC-Cond: 3rd Mon Feb\nX-SC-Duration: 19710515-\nX-SC-Record-Id: <Presidents_Day\@from.sctweb>\n",
241 "X-SC-Subject: Memorial Day\nX-SC-Category: Holiday\nX-SC-Cond: Last Mon May\nX-SC-Duration: 19710531-\nX-SC-Record-Id: <Memorial_Day\@from.sctweb>\n",
242 "X-SC-Subject: Independence Day\nX-SC-Category: Holiday\nX-SC-Cond: 4 Jul\nX-SC-Duration: 17760704-\nX-SC-Record-Id: <Independence_Day\@from.sctweb>\n",
243 "X-SC-Subject: Labor Day\nX-SC-Category: Holiday\nX-SC-Cond: 1st Mon Sep\nX-SC-Duration: 18840901-\nX-SC-Record-Id: <Labor_Day\@from.sctweb>\n",
244 "X-SC-Subject: Columbus Day\nX-SC-Category: Holiday\nX-SC-Cond: 2nd Mon Oct\nX-SC-Duration: 19711011-\nX-SC-Record-Id: <Columbus_Day\@from.sctweb>\n",
245 "X-SC-Subject: Veterans Day\nX-SC-Category: Holiday\nX-SC-Cond: 11 Nov\nX-SC-Duration: 19261111-\nX-SC-Record-Id: <Veterans_Day\@from.sctweb>\n",
246 "X-SC-Subject: Thanksgiving\nX-SC-Category: Holiday\nX-SC-Cond: 4th Thu Nov\nX-SC-Duration: 14921122-\nX-SC-Record-Id: <Thanksgiving\@from.sctweb>\n",
247 "X-SC-Subject: Christmas\nX-SC-Category: Holiday\nX-SC-Cond: 25 Dec\nX-SC-Duration: 00011225-\nX-SC-Record-Id: <Christmas\@from.sctweb>\n",
248 );
249 }
250
251 sub do_mhc_schedule {
252     $| = 1;
253     my %days = (M => "Mon", T => "Tue", W => "Wed", R => "Thu", F => "Fri", S => "Sat", U => "SU");
254     my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
255     my ($file, $current, @mhc, @schedule);
256     $file = $opts{'out'};
257     @schedule = get_schedule(@_);
258     @mhc = get_mhc_header;
259     if(defined($file) && (-d $file)) {
260         my @mhc2;
261         foreach (@mhc) {
262             $_ =~ s/X-SC-Subject: ([^\n]*)/X-SC-Subject: $1\nSubject: $1/;
263             $_ =~ s/X-SC-Category: ([^\n]*)/X-SC-Category: $1\nFrom: $1/;
264             $_ =~ s/X-SC-Duration: (\d\d\d\d)(\d\d)(\d\d)-/"X-SC-Duration: $1$2$3-\nDate: $3 " . $mon[$2-1] . " 1970 12:00:00 +0000"/e;
265             push @mhc2, $_;
266         }
267         @mhc = @mhc2;
268     }
269     foreach my $row (@schedule) {
270         map {s/\n/-/g if defined; $_} %$row;
271         my $id=generate_id($row->{'id'});
272         $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
273         $row->{'days'} =~ s/^ //;
274         #$row->{'duration'} =~ s/(\d\d)-(\d\d)-(\d\d)/20$3$1$2/g;
275         my @day = ();
276         @day = map { "!" . $_ } (@{$row->{'off'}}) if ($row->{'off'});
277         $current = "";
278         #print "# $id\n";
279         $current .= "X-SC-Subject: " . $row->{'title'} . "\n";
280         $current .= "X-SC-Location: " . $row->{'location'} . "\n";
281         $current .= "X-SC-Category: School\n";
282         $current .= "X-SC-Cond: " . $row->{'days'} . "\n";
283         $current .= "X-SC-Time: ".$row->{'begin'}."-".$row->{'end'}."\n";
284         $current .= "X-SC-Duration: " . $row->{'duration'} . "\n";
285         $current .= "X-SC-Day: @day\n" if(exists $day[0]);
286         $current .= "X-SC-Alarm: 15 minutes\n";
287         $current .= "X-SC-Record-Id: <".$row->{'id'}."\@from.sctweb>\n";
288         if(defined($file) && (-d $file)) {
289             my $email = get_faculty_email $row->{'instructor'};
290             $row->{'instructor'} = '"' . $row->{'instructor'} . '" <'. ($email || ($1 || "unknown") . "\@from.sctweb") . ">";
291             $row->{'duration'} =~ /^(\d\d\d\d)(\d\d)(\d\d)-\d{8}$/;
292             $row->{'begin'} =~ /^(\d\d):(\d\d)$/;
293             my $next = next_class(%$row);
294             my @date = Gmtime(Mktime($next->date,$1,$2,0));
295             $current .= sprintf "Date: %s, %2d %s %4d %02d:%02d:00 +0000\n", Day_of_Week_Abbreviation($date[7]), $date[2], $mon[$date[1]-1], $date[0], $date[3], $date[4], $date[5];
296             $current .= "Subject: " . $row->{'title'} . "\n";
297             $current .= "From: " . $row->{'instructor'} . "\n";
298         }
299         #print "\n$current";
300         push @mhc, $current;
301     }
302     if(defined($file) && (-d $file)) {
303         my @lines;
304         foreach my $name (<$file/[1-9]*>) {
305             next unless $name =~ /^$file\/[1-9][0-9]*$/;
306             open (FH, $name) || die $!;
307             @lines = <FH>;
308             close FH;
309             foreach (@lines) {
310                 unlink $name if /^X-SC-Record-Id: <.*\@from.sctweb>/;
311             }
312         }
313         my $i=0;
314         foreach (@mhc) {
315             while(-f ++$i) {}
316             open (FH, ">$file/$i") || die $!;
317             print FH $_;
318             close FH;
319         }
320     } else {
321         open(STDOUT, ">" . $file) || die $! if(defined($file));
322         print "# MHC school schedule\n# Autogenerated by sctweb ".localtime()."\n\n";
323         print join("\n", @mhc);
324     }
325 }
326
327 sub do_csv_schedule {
328     $| = 1;
329     my %days = (M => "Mon", T => "Tue", W => "Wed", R => "Thu", F => "Fri", S => "Sat", U => "SU");
330     my @mon = qw(Jan. Feb. Mar. Apr. May June July Aug. Sept. Oct. Nov. Dec.);
331     my ($current, @mhc, @schedule);
332     @schedule = get_schedule(@_);
333     open(STDOUT, ">" . $opts{'out'}) || die $! if(defined($opts{'out'}));
334     foreach my $row (@schedule) {
335         map {s/\n/-/g if defined; $_} %$row;
336         my $id=generate_id($row->{'id'});
337         $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
338         $row->{'days'} =~ s/^ //;
339         my $next = next_class(%$row);
340         $current = "";
341         #print "# $id\n";
342         $current .= $row->{'id'} . ",";
343         $current .= $row->{'title'} . ",";
344         my $instructor = $row->{'instructor'};
345         $instructor =~ s/ [A-Z. ]* / /;
346         $current .= '"' . $instructor . '",';
347         $next =~ /^(\d\d\d\d)(\d\d)(\d\d)$/;
348         $current .= $1 . "-". $2 ."-" . $3 . "\n";
349         print $current;
350     }
351 }
352
353 sub do_vcalendar_schedule {
354     $| = 1;
355     my %days = (M => "MO", T => "TU", W => "WE", R => "TH", F => "FR", S => "SA", U => "SU");
356     my $file = $opts{'out'};
357     my @schedule = get_schedule(@_);
358     open(STDOUT, ">>" . $file) || die $! if(defined($file) && (! -d $file));
359     open(STDOUT, ">/dev/null") || die $! if(defined($file) && (-d $file));
360     print "BEGIN:VCALENDAR\r\nVERSION:1.0\r\n";
361     foreach my $row (@schedule) {
362         map { s/\n/-/g; $_} %$row;
363         $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
364         $row->{'days'} =~ s/^ //;
365         my @day = ();
366         @day = @{$row->{'off'}} if ($row->{'off'});
367         my $day = "";
368         if(exists($day[0])) {
369             $day = join(";", @day);
370             $day =~ s/\b(\d{8})\b/$1T000000/g;
371         }
372         my ($starttime, $stoptime)=($row->{'begin'}, $row->{'end'});
373         my ($startdate, $stopdate)=split(/-/, $row->{'duration'});
374         $starttime =~ s/://;
375         $stoptime =~ s/://;
376         if(defined($file) && (-d $file)) {
377             open FH, ">$file/" . $row->{'id'} . ".vcs" or die "$!";
378             select FH;
379             print "BEGIN:VCALENDAR\r\nVERSION:1.0\r\n";
380         }
381         print "BEGIN:VEVENT\r\n";
382         print "SUMMARY:", $row->{'title'}, "\r\n";
383         print "DESCRIPTION:", $row->{'id'}, "\r\n";
384         print "LOCATION:", $row->{'location'}, "\r\n";
385         print "CATEGORIES:Education\r\n";
386         print "DTSTART:", first_class(%$row)."T".$starttime, "00\r\n";
387         print "DTEND:", first_class(%$row)."T".$stoptime, "00\r\n";
388         print "RRULE:W1 ", $row->{'days'} . " $stopdate", "T000000\r\n";
389         print("EXDATE:$day\r\n") if($day);
390         print "ATTENDEE;ROLE=OWNER;STATUS=CONFIRMED:", $opts{'name'}, "\r\n" if(defined($opts{'name'}));
391         print "ATTENDEE;ROLE=ORGANIZER;STATUS=CONFIRMED:", $row->{'instructor'}, " <" . (get_faculty_email($row->{'instructor'}) || "fake\@ddress"), ">\r\n";
392         print "END:VEVENT\r\n";
393         if(defined($file) && (-d $file)) {
394             print "END:VCALENDAR\r\n";
395             close FH;
396             select STDOUT;
397         }
398     }
399     print "END:VCALENDAR\r\n";
400 }
401
402 sub do_xml_schedule {
403     my $file = $opts{'out'};
404     my $schedule = { class => [ get_schedule(@_) ] };
405     my $xml = XMLout($schedule, NoAttr => 1, RootName => 'schedule');
406     if($file) {
407         open FH, ">$file" || die $!;
408         print FH $xml;
409         close FH;
410     } else {
411         print $xml;
412     }
413 }
414
415 sub do_html_schedule {
416     my @showheaders = ("Section ID/Title", "Instructor", "Days", "Time", "Duration", "Location");
417     my $shade = "dark";
418     my @schedule = get_schedule(@_);
419     if($opts{'out'}) {
420         open (FH, ">".$opts{'out'}) || die $!;
421         select FH;
422     }
423     print '<table id="schedule" cellpadding="3" cellspacing="0">'."\n<tr><th>";
424     print join("</th><th>",@showheaders);
425     print "</th></tr>\n";
426         foreach my $row (@schedule) {
427             map { s/\n/<br \/>/g; $_} %$row;
428             $row->{'duration'} =~ s/-/<br \/>/g;
429             $row->{'duration'} =~ s/\d\d(\d\d)(\d\d)(\d\d)/$2-$3-$1/g;
430             print '<tr class="'.$shade.'">';
431             $shade = ($shade eq "dark"?"light":"dark");
432             print '<td class="idtitle">';
433             print '<span class="sectionid">' .$row->{'id'}. '</span><br />';
434             print '<span class="coursetitle">' .$row->{'title'}. '</span></td>';
435             my $instructor = $row->{'instructor'};
436             #$instructor =~ s/ [A-Z. ]* / /;
437             my $url = get_faculty_url($row->{'instructor'});
438             if($url) {
439                 print '<td class="instructor"><a href="' . $url . '">'
440                 . $row->{'instructor'} . "</a></td>";
441             } else {
442                 print '<td class="instructor">' . $instructor . "</td>";
443             }
444             print "<td>" . $row->{'days'} . "</td>";
445             my ($a,$b) = ($row->{'begin'}, $row->{'end'});
446             $b .= "AM";
447             $a=~s/(1[3-9]|2\d|00):(\d\d)/sprintf "%d:%02d",abs $1-12,$2/e;
448             $b=~s/(1[3-9]|2\d|00):(\d\d)AM/sprintf "%d:%02dPM",abs $1-12,$2/e;
449             print "<td>$a-<wbr />$b</td>";
450             print "<td>" . $row->{'duration'} . "</td>";
451             print "<td>" . $row->{'location'} . "</td>";
452             print "</tr>\n";
453         }
454     print "</table>\n";
455     select STDOUT;
456 }
457
458 sub do_html_grades {
459     my $grades;
460     my @showheaders = ("Section ID", "Course Title", "Grade", "Earned<br />Hours", "Quality<br />Hours", "Quality<br />Points");
461     $grades = get_grades(@_);
462     my ($row);
463     my $shade = "dark";
464     if($opts{'out'}) {
465         open (FH, ">".$opts{'out'}) || die $!;
466         select FH;
467     }
468     print '<table id="grades" cellpadding="3" cellspacing="0">'."\n<tr>";
469     print '<th align="left" class="sectionid">', $showheaders[0];
470     print '</th><th align="left" class="coursetitle">', $showheaders[1];
471     print '</th><th align="center" class="grade">';
472     print join('</th><th align="center" class="right-number">',@showheaders[2 .. 5]);
473     print "</th></tr>\n";
474     foreach my $ts ($grades->{'class'}) {
475         foreach my $row (@$ts) {
476             print '<tr class="'.$shade.'">';
477             $shade = ($shade eq "dark"?"light":"dark");
478             print '<td align="left" class="sectionid">', $row->{'id'}, '</td>';
479             print '<td align="left" class="coursetitle">', $row->{'title'}, '</td>';
480             print '<td align="center" class="grade">';
481             #print join('</td><td>', @$row[0 .. 1]);
482             print join('</td><td align="right" class="right-number">', ($row->{'grade'},$row->{'earned'},$row->{'hours'},$row->{'points'}));
483             print "</td></tr>\n";
484         }
485     }
486     my $lastrow = $grades->{'cumulative'}->[scalar @{$grades->{'cumulative'}}-1];
487     print '<tr class="cumulative '.$shade.'"><td id="cumulative" colspan="2">Cumulative: through ', capitalize($lastrow->{'term'});
488     print '</td><td align="center" id="gpa" class="grade">';
489     print $lastrow->{'gpa'};
490     print '</td><td align="right" class="right-number">';
491     print join('</td><td align="right" class="right-number">', ($lastrow->{'earned'}, $lastrow->{'hours'}, $lastrow->{'points'}));
492     print "</td></tr>\n";
493     print "</table>\n";
494     select STDOUT;
495 }
496
497
498 if ($opts{'format'} eq "xml") {
499     do_xml_schedule(@ARGV);
500 } elsif ($opts{'format'} eq "html") {
501     do_html_schedule(@ARGV);
502 } elsif ($opts{'format'} eq "mhc") {
503     do_mhc_schedule(@ARGV);
504 } elsif ($opts{'format'} eq "csv") {
505     do_csv_schedule(@ARGV);
506 } elsif ($opts{'format'} eq "vcs") {
507     do_vcalendar_schedule(@ARGV);
508 } elsif ($opts{'format'} eq "grades") {
509     do_html_grades(@ARGV);
510 } else {
511     die "Unknown format.  Try specifying --format.\n"
512 }