- return @schedule;
-}
-
-sub get_faculty_email {
- my ($name, $school, $email);
- if((-f $ENV{'HOME'} . "/public_html/faculty.csv") && ! %faculty) {
- open INS, $ENV{'HOME'} . "/public_html/faculty.csv";
- while($_ = <INS>) {
- chomp;
- m/"([^"]*)",([^,]*),([^,]*)/;
- ($name, $school, $email) = ($1, $2, $3);
- $name =~ s/^([^,]*), ([^,]*)(.*)$/$2 $1$3/;
- $name =~ s/ [A-Z]\.//g;
- $name = lc $name;
- $name =~ s/\W//g;
- $faculty{$name} = $email;
- }
- }
- $name = shift;
- $name =~ s/ [A-Z]r?\.//g;
- $name = lc $name;
- $name =~ s/\W//g;
- return $faculty{$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: <New_Years_Day\@from.sctweb>\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: <Martin_Luther_King_Jr_Day\@from.sctweb>\n",
-"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",
-"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",
-"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",
-"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",
-"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",
-"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",
-"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",
-"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",
-);
-}
-
-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 = shift unless (!defined $_[0] or $_[0] =~ /^\d/);
- @schedule = get_schedule(@_);
- @mhc = get_mhc_header;
- if(defined($file) && (-d $file)) {
- my @mhc2;
- 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] . " 2037 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'});
- $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 = map { "!" . $_ } (off_for_holidays(%$row),off_for_exams(%$row));
- $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)) {
- $row->{'instructor'} =~ s/^([^,]*), ([^,]*)(.*)/$2 $1$3/;
- my $email = get_faculty_email $row->{'instructor'};
- $row->{'instructor'} = '"' . $row->{'instructor'} . '" <'. ($email || "$1\@from.sctweb" . ">");
- $row->{'duration'} =~ /^(\d\d\d\d)(\d\d)(\d\d)-\d{8}$/;
- $row->{'begin'} =~ /^(\d\d):(\d\d)$/;
- my $next = next_class(%$row);
- 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;
- @lines = <FH>;
- close FH;
- foreach (@lines) {
- unlink $name if /^X-SC-Record-Id: <.*\@from.sctweb>/;
- }
- }
- my $i=0;
- foreach (@mhc) {
- while(-f ++$i) {}
- open FH, ">$file/$i" or die $!;
- print FH $_;
- close FH;
+ foreach my $ts ($tf->table_states) {
+ foreach my $row ($ts->rows) {
+ next if ($row->[0] =~ /Total Enrolled Hours/);
+ $row->[1] =~ s/\xa0/ /g;
+ map { s/\xa0//g; $_} @$row;
+ map { s/^\r?\n? *//g; $_} @$row;
+ $row->[0] =~ s/.*launchWebCT\("([^"]*)"[^)]*\).*>\s*//s;
+ $classid=$1;
+ $row->[0] =~ s/(.*)/capitalize($1)/eg;
+ $row->[1] =~ s/^([MTWRFS]*) *([0-9:-]*[AP]M)\s*//;
+ ($days, $times) = ($1, $2);
+ ($begin, $end) = split("-", $times);
+ if($times =~ /^(\d\d):\d\d-(\d\d):\d\dPM$/) {
+ if($1 < $2 && $2 != 12) {
+ $begin =~ s/^(\d\d)/$1+12/e;
+ }
+ if($2 != 12) {
+ $end =~ s/^(\d\d)/$1+12/e;
+ }
+ $end =~ s/PM$//;
+ } else { $end =~ s/AM$//; }
+ $row->[2] =~ s/(.*\S)\s*//;
+ $session = $1;
+ $row->[2] =~ s/(\d\d)-(\d\d)-(\d\d)/20$3$1$2/g;
+ $row->[2] =~ s/ *to */-/g;
+ $row->[3] = capitalize($row->[3]);
+ $row->[3] =~ s/([A-Z]r?)$/$1./;
+ $row->[3] =~ s/^([^,]*), ([^,.]{3}[^,]*)/$2 $1/;
+ my %class = (
+ id => $classid,
+ title => $row->[0],
+ #session => $session,
+ instructor => $row->[3],
+ credits => $row->[4],
+ crn => $row->[5],
+ #gradetype => $row->[6],
+ days => $days,
+ #'time' => $times,
+ begin => $begin,
+ end => $end || undef,
+ duration => $row->[2],
+ location => $row->[1],
+ #message => $row->[7],
+ );
+ my @off = ( map { "$_"; } (off_for_holidays(%class), off_for_exams(%class)));
+ $class{'off'} = [ @off ] if (@off);
+ push @schedule, \%class;