#!/usr/bin/perl -w # $Id$ # -*- perl -*- vim: ft=perl sw=4 sts=4 # Brief usage instructions: # Create a ~/.schedprocrc that has schedule=/path/to/schedule.xml and # grades=/path/to/grades.xml. HTTP URLs are acceptable use strict; 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); use Date::Calendar::Profiles qw($Profiles); use Date::Calendar::Year; use Getopt::Long; use LWP::UserAgent; use XML::Simple; use vars qw(%opts %faculty %facurl); $opts{'config'} = $ENV{HOME} . "/.schedprocrc"; my $arg = $ARGV[0] || ""; if($arg eq "-x") { shift; $opts{'format'} = "xml"; } elsif($arg eq "-h") { shift; $opts{'format'} = "html"; } elsif($arg eq "-m") { shift; $opts{'format'} = "mhc"; } elsif($arg eq "-c") { shift; $opts{'format'} = "csv"; } elsif($arg eq "-v") { shift; $opts{'format'} = "vcs"; } elsif($arg eq "-g") { shift; $opts{'format'} = "grades"; } Getopt::Long::Configure ("bundling", "auto_help"); die "Invalid arguments\n" unless GetOptions(\%opts, 'schedule|S=s', 'grades|G=s', 'faculty=s', 'name|n=s', 'email|e=s', 'format|f=s', 'config|F=s', 'out|o=s'); if (-r $opts{'config'}) { open CONFIG, $opts{'config'} or die $!; while() { s/\#.*//; next unless m/^([^=]*)=(.*)/; my ($l, $r) = ($1, $2); if ($l =~ /^(schedule|grades|name|email|faculty)$/) { $opts{$l}=$r unless(defined($opts{$l})); } else { warn "Unknown config file option $l.\n"; } } close CONFIG; } $opts{'schedule'} ||= "~/schedule.xml"; $opts{'grades'} ||= "~/grades.xml"; $opts{'faculty'} ||= ""; $opts{'schedule'} =~ s/(^|,)~\//$1$ENV{HOME}\//; $opts{'grades'} =~ s/(^|,)~\//$1$ENV{HOME}\//; $opts{'faculty'} =~ s/(^|,)~\//$1$ENV{HOME}\//; if(!defined($opts{'out'}) && defined($ARGV[0])) { $opts{'out'} = shift; } if(!defined($opts{'format'}) && defined($opts{'out'})) { $opts{'format'} = $opts{'out'}; $opts{'format'} =~ s/.*\.//; $opts{'format'} =~ s/^(.*\/|)\.?schedule$/mhc/; undef $opts{'out'} if($opts{'out'} =~ /^(html|mhc|csv|vcs|ics|xml|grades)$/); } $opts{'format'} ||= ""; undef $opts{'out'} if(($opts{'out'}||"") eq "-"); sub generate_id { my ($section, $number) = split("-", shift); my $id = 0; foreach my $c (split //, $section) {$id=26*$id+(ord($c)-1)%32;} $id=10000*$id+$number; return $id; } sub first_class { my %days = (M => 1, T => 2, W => 3, R => 4, F => 5, S => 6, U => 7); my %class = @_; $class{'duration'} =~ /(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)/; my $days = Delta_Days($1,$2,$3,$4,$5,$6); my $firstday = Date::Calc->new($1,$2,$3); my $lastday = Date::Calc->new($4,$5,$6); my $today; my @days=(); foreach my $d (split("",$class{'days'})) { push @days, $days{$d}; } my @off = (); @off = @{$class{'off'}} if ($class{'off'}); for($today = $firstday; $today < $lastday; $today++) { next unless(grep($_ == Day_of_Week($today->date), @days)); next if(grep($_ == "$today", @off)); return $today; } return undef; } sub next_class { my %days = (M => 1, T => 2, W => 3, R => 4, F => 5, S => 6, U => 7); my %class = @_; $class{'duration'} =~ /(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)/; my $days = Delta_Days($1,$2,$3,$4,$5,$6); my $firstday = Date::Calc->new($1,$2,$3); my $lastday = Date::Calc->new($4,$5,$6); my $today = Date::Calc->new(Date::Calc->localtime(time+3600*6)->date); my @days=(); foreach my $d(split("",$class{'days'})) { push @days, $days{$d}; } my @off = (); @off = @{$class{'off'}} if ($class{'off'}); for($today = ($today > $firstday ? $today : $firstday); $today < $lastday; $today++) { next unless(grep($_ == Day_of_Week($today->date), @days)); next if(grep($_ == "$today", @off)); return $today; } $today = Date::Calc->new(Date::Calc->gmtime->date); for($today = ($today < $lastday ? $today : $lastday); $today > $firstday; $today--) { next unless(grep($_ == Day_of_Week($today->date), @days)); next if(grep($_ == "$today", @off)); return $today; } return undef; } sub vcal_datetime { my $date=shift; my $time=shift; $date =~ /(\d\d\d\d)(\d\d)(\d\d)/; my ($y,$m,$d)=($1,$2,$3); $time =~ /(\d\d):?(\d\d)/; my $day=Date::Calc->gmtime(Mktime($y,$m,$d,$1,$2,0)); return sprintf ("%02d%02d%02dT%02d%02d%02dZ", $day->year(), $day->month(), $day->day(), $day->time()); } sub capitalize { local $_ = shift || ""; s/ +$//; s/\b([A-Z])([A-Z]*)\b/$1\L$2/g; s/\b(I)(i*)\b/$1\U$2/g; s/\bUs\b/US/g; s/ (And|For|Of|Or|The|To|With) / \l$1 /g; s/\b(Mc)([a-z])/$1\u$2/g; s/\b(Tcp\/Ip|Pc|Tba)\b/\U$&/g; s/\bThru\b/Through/g; s/\bAcct\b/Accounting/g; s/\bAmer\b/American/g; s/\bChem\b/Chemistry/g; s/\bComp\b/Composition/g; s/\bFed\b/Federal/g; s/\bGen\b/General/g; s/\bIntro\b/Introduction/g; s/\bPrgm\b/Programming/g; s/\bOp Sys\b/Operating System/g; #s/\bGovt\b/Government/g; s/\bLit\b/Literature/g; s/\bPrin\b/Principles/g; s/\bBus\b/Business/g; s/\bSyst\b/Sys/g; return $_; } sub read_fileurl { my $content; my $url=shift; if($url =~ /:\/\//) { my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; # $ua->cookie_jar( {} ); my $response = $ua->get("$url") or die "$!"; if($response->is_success) { $content = $response->content; } else { die "$!" unless $_[0]; } } else { if(open(F,$url)) { $content = join ("", ); close F; } else { die "$!" unless $_[0]; } } return $content||""; #my $ref = XMLin($content, ForceArray => [ 'class', 'cumulative', 'off' ], KeyAttr => ""); #return @{$ref->{'class'}}; } sub get_schedule { my $content = read_fileurl($opts{'schedule'}); my $ref = XMLin($content, ForceArray => [ 'class', 'off' ], KeyAttr => ""); die "Could not load schedule.\n" unless $ref->{'class'}; return @{$ref->{'class'}}; } sub get_grades { my $content = read_fileurl($opts{'grades'}); my $ref = XMLin($content, ForceArray => [ 'class', 'cumulative' ], KeyAttr => ""); return $ref; } sub load_faculty { my ($name, $email, $url, $content); if(($opts{'faculty'}) && ! %faculty) { $faculty{'done'} = "true"; $content = read_fileurl($opts{'faculty'},1); foreach my $f (split("\n", $content)) { ($name, $email, $url) = $f =~ m/"([^"]*)",([^,]*),([^,]*)/; # " next unless ($name); $name =~ s/ [A-Z]\.//g; $name = lc $name; $name =~ s/\W//g; $faculty{$name} = $email if($email); $facurl{$name} = $url if ($url); } } } sub get_faculty_email { load_faculty(); my ($name); $name = shift; $name =~ s/ [A-Z]r?\.//g; $name = lc $name; $name =~ s/\W//g; return $faculty{$name}; } sub get_faculty_url { load_faculty(); my ($name); $name = shift; $name =~ s/ [A-Z]r?\.//g; $name = lc $name; $name =~ s/\W//g; return $facurl{$name}; } sub get_mhc_header { return ( "X-SC-Subject: New Years Day\nX-SC-Category: Holiday\nX-SC-Cond: 1 Jan\nX-SC-Duration: 00010101-\nX-SC-Record-Id: \n", "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: \n", "X-SC-Subject: Presidents Day\nX-SC-Category: Holiday\nX-SC-Cond: 3rd Mon Feb\nX-SC-Duration: 19710515-\nX-SC-Record-Id: \n", "X-SC-Subject: Memorial Day\nX-SC-Category: Holiday\nX-SC-Cond: Last Mon May\nX-SC-Duration: 19710531-\nX-SC-Record-Id: \n", "X-SC-Subject: Independence Day\nX-SC-Category: Holiday\nX-SC-Cond: 4 Jul\nX-SC-Duration: 17760704-\nX-SC-Record-Id: \n", "X-SC-Subject: Labor Day\nX-SC-Category: Holiday\nX-SC-Cond: 1st Mon Sep\nX-SC-Duration: 18840901-\nX-SC-Record-Id: \n", "X-SC-Subject: Columbus Day\nX-SC-Category: Holiday\nX-SC-Cond: 2nd Mon Oct\nX-SC-Duration: 19711011-\nX-SC-Record-Id: \n", "X-SC-Subject: Veterans Day\nX-SC-Category: Holiday\nX-SC-Cond: 11 Nov\nX-SC-Duration: 19261111-\nX-SC-Record-Id: \n", "X-SC-Subject: Thanksgiving\nX-SC-Category: Holiday\nX-SC-Cond: 4th Thu Nov\nX-SC-Duration: 14921122-\nX-SC-Record-Id: \n", "X-SC-Subject: Christmas\nX-SC-Category: Holiday\nX-SC-Cond: 25 Dec\nX-SC-Duration: 00011225-\nX-SC-Record-Id: \n", ); } sub do_mhc_schedule { $| = 1; my %days = (M => "Mon", T => "Tue", W => "Wed", R => "Thu", F => "Fri", S => "Sat", U => "SU"); my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my ($file, $current, @mhc, @schedule); $file = $opts{'out'}; @schedule = get_schedule(@_); @mhc = get_mhc_header; if(defined($file) && (-d $file)) { my @mhc2; local $_; foreach (@mhc) { s/X-SC-Subject: ([^\n]*)/X-SC-Subject: $1\nSubject: $1/; s/X-SC-Category: ([^\n]*)/X-SC-Category: $1\nFrom: $1/; 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; push @mhc2, $_; } @mhc = @mhc2; } foreach my $row (@schedule) { map {s/\n/-/g if defined; $_} %$row; my $id=generate_id($row->{'id'}); my $next = next_class(%$row); $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g; $row->{'days'} =~ s/^ //; #$row->{'duration'} =~ s/(\d\d)-(\d\d)-(\d\d)/20$3$1$2/g; my @day = (); @day = map { "!$_" } (@{$row->{'off'}}) if ($row->{'off'}); $current = ""; #print "# $id\n"; $current .= "X-SC-Subject: " . $row->{'title'} . "\n"; $current .= "X-SC-Location: " . $row->{'location'} . "\n"; $current .= "X-SC-Category: School\n"; $current .= "X-SC-Cond: " . $row->{'days'} . "\n"; $current .= "X-SC-Time: ".$row->{'begin'}."-".$row->{'end'}."\n"; $current .= "X-SC-Duration: " . $row->{'duration'} . "\n"; $current .= "X-SC-Day: @day\n" if(exists $day[0]); $current .= "X-SC-Alarm: 15 minutes\n"; $current .= "X-SC-Record-Id: <".$row->{'id'}."\@from.sctweb>\n"; if(defined($file) && (-d $file)) { my $email = get_faculty_email $row->{'instructor'}; $row->{'instructor'} = '"' . $row->{'instructor'} . '" <'. ($email || ($1 || "unknown") . "\@from.sctweb") . ">"; $row->{'duration'} =~ /^(\d\d\d\d)(\d\d)(\d\d)-\d{8}$/; $row->{'begin'} =~ /^(\d\d):(\d\d)$/; my @date = Gmtime(Mktime($next->date,$1,$2,0)); $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]; $current .= "Subject: " . $row->{'title'} . "\n"; $current .= "From: " . $row->{'instructor'} . "\n"; } #print "\n$current"; push @mhc, $current; } if(defined($file) && (-d $file)) { my @lines; foreach my $name (<$file/[1-9]*>) { next unless $name =~ /^$file\/[1-9][0-9]*$/; open (FH, $name) || die $!; @lines = ; close FH; foreach (@lines) { unlink $name if /^X-SC-Record-Id: <.*\@from.sctweb>/; } } my $i=0; foreach my $h (@mhc) { while(-f ++$i) {} open (FH, ">$file/$i") || die $!; print FH $h; close FH; } } else { open(STDOUT, ">" . $file) || die $! if(defined($file)); print "# MHC school schedule\n# Autogenerated by sctweb ".localtime()."\n\n"; print join("\n", @mhc); } } sub do_csv_schedule { $| = 1; my %days = (M => "Mon", T => "Tue", W => "Wed", R => "Thu", F => "Fri", S => "Sat", U => "SU"); my @mon = qw(Jan. Feb. Mar. Apr. May June July Aug. Sept. Oct. Nov. Dec.); my ($current, @mhc, @schedule); @schedule = get_schedule(@_); open(STDOUT, ">" . $opts{'out'}) || die $! if(defined($opts{'out'})); foreach my $row (@schedule) { map {s/\n/-/g if defined; $_} %$row; my $id=generate_id($row->{'id'}); my $next = next_class(%$row); $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g; $row->{'days'} =~ s/^ //; $current = ""; #print "# $id\n"; $current .= $row->{'id'} . ","; $current .= $row->{'title'} . ","; my $instructor = $row->{'instructor'}; $instructor =~ s/ [A-Z. ]* / /; $current .= '"' . $instructor . '",'; $next =~ /^(\d\d\d\d)(\d\d)(\d\d)$/; $current .= $1 . "-". $2 ."-" . $3 . "\n"; print $current; } } sub do_vcalendar_schedule { $| = 1; my %days = (M => "MO", T => "TU", W => "WE", R => "TH", F => "FR", S => "SA", U => "SU"); my $file = $opts{'out'}; my @schedule = get_schedule(@_); open(STDOUT, ">" . $file) || die $! if(defined($file) && (! -d $file)); open(STDOUT, ">/dev/null") || die $! if(defined($file) && (-d $file)); print "BEGIN:VCALENDAR\r\nVERSION:1.0\r\n"; foreach my $row (@schedule) { map { s/\n/-/g; $_} %$row; my ($starttime, $stoptime)=($row->{'begin'}, $row->{'end'}); my ($startdate, $stopdate)=split(/-/, $row->{'duration'}); $starttime =~ s/://; $stoptime =~ s/://; my $first = first_class(%$row); my @day = (); @day = @{$row->{'off'}} if ($row->{'off'}); my $day = ""; if(exists($day[0])) { $day = join(";", @day); $day =~ s/\b(\d{8})\b/$1T${starttime}00/g; } if(defined($file) && (-d $file)) { open FH, ">$file/" . $row->{'id'} . ".vcs" or die "$!"; select FH; print "BEGIN:VCALENDAR\r\nVERSION:1.0\r\n"; } print "BEGIN:VEVENT\r\n"; print "SUMMARY:", $row->{'title'}, "\r\n"; print "DESCRIPTION:", $row->{'id'}, "\r\n"; print "LOCATION:", $row->{'location'}, "\r\n"; print "CATEGORIES:Education\r\n"; print "DTSTART:", vcal_datetime($first,$starttime), "\r\n"; print "DTEND:", vcal_datetime($first,$stoptime), "\r\n"; #print "DTSTART:", $first."T".$starttime, "00\r\n"; #print "DTEND:", $first."T".$stoptime, "00\r\n"; $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g; $row->{'days'} =~ s/^ //; print "RRULE:W1 ", $row->{'days'} . " $stopdate", "T000000\r\n"; print("EXDATE:$day\r\n") if($day); print "ATTENDEE;ROLE=OWNER;STATUS=CONFIRMED:", $opts{'name'}, ($opts{'email'}?" <".$opts{'email'}.">":""), "\r\n" if(defined($opts{'name'})); print "ATTENDEE;ROLE=ORGANIZER;STATUS=CONFIRMED:", $row->{'instructor'}, " <" . (get_faculty_email($row->{'instructor'}) || "fake\@ddress"), ">\r\n"; print "END:VEVENT\r\n"; if(defined($file) && (-d $file)) { print "END:VCALENDAR\r\n"; close FH; select STDOUT; } } print "END:VCALENDAR\r\n"; } sub do_icalendar_schedule { $| = 1; my $r="\r"; # Ugh, I can't find a better solution than hardwiring it to CST my $tzn = "America/Chicago"; my $timezone = <now(); $now = sprintf ("%02d%02d%02dT%02d%02d%02dZ", $now->datetime()); my %days = (M => "MO", T => "TU", W => "WE", R => "TH", F => "FR", S => "SA", U => "SU"); my $file = $opts{'out'}; my @schedule = get_schedule(@_); open(STDOUT, ">" . $file) || die $! if(defined($file) && (! -d $file)); open(STDOUT, ">/dev/null") || die $! if(defined($file) && (-d $file)); print "BEGIN:VCALENDAR$r\nPRODID:-//Tim Pope//NONSGML Schedproc//EN$r\nVERSION:2.0$r\nMETHOD:PUBLISH$r\n$timezone"; foreach my $row (@schedule) { map { s/\n/-/g; $_} %$row; my ($starttime, $stoptime)=($row->{'begin'}, $row->{'end'}); my ($startdate, $stopdate)=split(/-/, $row->{'duration'}); $starttime =~ s/://; $stoptime =~ s/://; my $first = first_class(%$row); my @day = (); @day = @{$row->{'off'}} if ($row->{'off'}); my $day = ""; if(exists($day[0])) { $day = join(",", @day); #$day =~ s/\b(\d{8})\b/$1T${starttime}00/g; } if(defined($file) && (-d $file)) { open FH, ">$file/" . $row->{'id'} . ".vcs" or die "$!"; select FH; print "BEGIN:VCALENDAR$r\nPRODID:-//Tim Pope//NONSGML Schedproc//EN$r\nVERSION:2.0$r\nMETHOD:PUBLISH$r\n$timezone"; } print "BEGIN:VEVENT$r\n"; print "ORGANIZER:mailto:" . $opts{'email'} . "$r\n" if $opts{'email'}; print "UID:" . $row->{'id'} . "\@from.sctweb$r\n"; print "DTSTAMP:$now$r\n"; print "SUMMARY:", $row->{'title'}, "$r\n"; print "DESCRIPTION:", $row->{'id'}, "$r\n"; print "LOCATION:", $row->{'location'}, "$r\n"; print "CATEGORIES:Education$r\n"; print "TRANSP:OPAQUE$r\n"; print "DTSTART;TZID=\"$tzn\":", $first."T".$starttime, "00$r\n"; print "DTEND;TZID=\"$tzn\":", $first."T".$stoptime, "00$r\n"; $row->{'days'} =~ s/([MTWRFS])/,$days{$1}/g; $row->{'days'} =~ s/^,//; #$stopdate++; print "RRULE:FREQ=WEEKLY;UNTIL=${stopdate}T000000Z;BYDAY=", $row->{'days'}, "$r\n"; #print("EXDATE;TZID=\"$tzn\":$day$r\n") if($day); print("EXDATE;VALUE=DATE:$day$r\n") if($day); print "ATTENDEE;CN=".$row->{'instructor'}.";RSVP=FALSE;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:" . (get_faculty_email($row->{'instructor'}) || "fake\@ddress"), "$r\n"; print "ATTENDEE;CN=".$opts{'name'}.";RSVP=FALSE;PARTSTAT=ACCEPTED;ROLE=REQ-PARTICIPANT:mailto:" . ($opts{'email'} || "fake\@ddress"), "$r\n" if $opts{'name'}; print "END:VEVENT$r\n"; if(defined($file) && (-d $file)) { print "END:VCALENDAR$r\n"; close FH; select STDOUT; } } print "END:VCALENDAR$r\n"; } sub do_xml_schedule { my $file = $opts{'out'}; my $schedule = { class => [ get_schedule(@_) ] }; my $xml = XMLout($schedule, NoAttr => 1, RootName => 'schedule'); if($file) { open FH, ">$file" || die $!; print FH $xml; close FH; } else { print $xml; } } sub do_html_schedule { my @showheaders = ("Section ID/Title", "Instructor", "Days", "Time", "Duration", "Location"); my $shade = "dark"; my @schedule = get_schedule(@_); if($opts{'out'}) { open (FH, ">".$opts{'out'}) || die $!; select FH; } print ''."\n\n"; foreach my $row (@schedule) { map { s/\n/
/g; $_} %$row; $row->{'duration'} =~ s/-/
/g; $row->{'duration'} =~ s/\d\d(\d\d)(\d\d)(\d\d)/$2-$3-$1/g; print ''; $shade = ($shade eq "dark"?"light":"dark"); print ''; my $instructor = $row->{'instructor'}; #$instructor =~ s/ [A-Z. ]* / /; my $url = get_faculty_url($row->{'instructor'}); if($url) { print '"; } else { print '"; } print ""; my ($a,$b) = ($row->{'begin'}, $row->{'end'}); $b .= "AM"; $a=~s/(1[3-9]|2\d|00):(\d\d)/sprintf "%d:%02d",abs $1-12,$2/e; $b=~s/(1[3-9]|2\d|00):(\d\d)AM/sprintf "%d:%02dPM",abs $1-12,$2/e; print ""; print ""; print ""; print "\n"; } print "
"; print join("",@showheaders); print "
'; print '' .$row->{'id'}. '
'; print '' .$row->{'title'}. '
' . $row->{'instructor'} . "' . $instructor . "" . $row->{'days'} . "$a-$b" . $row->{'duration'} . "" . (ref($row->{'location'})?"":$row->{'location'}) . "
\n"; select STDOUT; } sub do_html_grades { my $grades; my @showheaders = ("Section ID", "Course Title", "Grade", "Earned
Hours", "Quality
Hours", "Quality
Points"); $grades = get_grades(@_); my ($row); my $shade = "dark"; if($opts{'out'}) { open (FH, ">".$opts{'out'}) || die $!; select FH; } print ''."\n"; print '\n"; foreach my $ts ($grades->{'class'}) { foreach my $row (@$ts) { print ''; $shade = ($shade eq "dark"?"light":"dark"); print ''; print ''; print '\n"; } } if(exists($grades->{'cumulative'})) { my $lastrow = $grades->{'cumulative'}->[scalar @{$grades->{'cumulative'}}-1]; print '\n"; } print "
', $showheaders[0]; print '', $showheaders[1]; print ''; print join('',@showheaders[2 .. 5]); print "
', $row->{'id'}, '', $row->{'title'}, ''; #print join('', @$row[0 .. 1]); print join('', ($row->{'grade'},$row->{'earned'},$row->{'hours'},$row->{'points'})); print "
Cumulative: through ', capitalize($lastrow->{'term'}); print ''; print $lastrow->{'gpa'}; print ''; print join('', ($lastrow->{'earned'}, $lastrow->{'hours'}, $lastrow->{'points'})); print "
\n"; select STDOUT; } if ($opts{'format'} eq "xml") { do_xml_schedule(@ARGV); } elsif ($opts{'format'} eq "html") { do_html_schedule(@ARGV); } elsif ($opts{'format'} eq "mhc") { do_mhc_schedule(@ARGV); } elsif ($opts{'format'} eq "csv") { do_csv_schedule(@ARGV); } elsif ($opts{'format'} eq "vcs") { do_vcalendar_schedule(@ARGV); } elsif ($opts{'format'} eq "ics") { do_icalendar_schedule(@ARGV); } elsif ($opts{'format'} eq "grades") { do_html_grades(@ARGV); } else { die "Unknown format. Try specifying --format.\n" }