Faculty URL
authorTim Pope <code@tpope.net>
Sat, 20 Aug 2005 07:34:54 +0000 (07:34 +0000)
committerTim Pope <code@tpope.net>
Sat, 20 Aug 2005 07:34:54 +0000 (07:34 +0000)
perl/schedproc

index dab1f18a49ed29ac911e6973079d47ad61e68bd9..8c45f83bbd334fde796f909982f554c92be2b348 100755 (executable)
@@ -13,15 +13,10 @@ use Date::Calendar::Year;
 use Getopt::Long;
 use LWP::UserAgent;
 use XML::Simple;
-use vars qw(%opts %faculty);
+use vars qw(%opts %faculty %facurl);
 
 $opts{'config'} = $ENV{HOME} . "/.schedprocrc";
 
-if(($ARGV[0] || "") eq '-F') {
-    shift;
-    $opts{'config'} = shift;
-}
-
 my $arg = $ARGV[0] || "";
 if($arg eq "-x") {
     shift;
@@ -45,7 +40,7 @@ if($arg eq "-x") {
 
 Getopt::Long::Configure ("bundling", "auto_help");
 die "Invalid arguments\n" unless
-GetOptions(\%opts, 'schedule=s', 'grades=s', 'name=s', 'format|f=s', 'config|F=s', 'out|o=s');
+GetOptions(\%opts, 'schedule|S=s', 'grades|G=s', 'facmail=s', 'facurl=s', 'name|n=s', 'format|f=s', 'config|F=s', 'out|o=s');
 
 if (-r $opts{'config'}) {
     open CONFIG, $opts{'config'} or die $!;
@@ -53,7 +48,7 @@ if (-r $opts{'config'}) {
        s/\#.*//;
        next unless m/^([^=]*)=(.*)/;
        my ($l, $r) = ($1, $2);
-       if ($l =~ /^(schedule|grades|name)$/) {
+       if ($l =~ /^(schedule|grades|name|facmail|facurl)$/) {
            $opts{$l}||=$r;
        } else {
            warn "Unknown config file option $l.\n";
@@ -64,9 +59,13 @@ if (-r $opts{'config'}) {
 
 $opts{'schedule'} ||= "~/schedule.xml";
 $opts{'grades'} ||= "~/grades.xml";
+$opts{'facmail'} ||= "";
+$opts{'facurl'} ||= "";
 
-$opts{'schedule'} =~ s/^~\//$ENV{HOME}\//;
-$opts{'grades'} =~ s/^~\//$ENV{HOME}\//;
+$opts{'schedule'} =~ s/(^|,)~\//$1$ENV{HOME}\//;
+$opts{'grades'} =~ s/(^|,)~\//$1$ENV{HOME}\//;
+$opts{'facmail'} =~ s/(^|,)~\//$1$ENV{HOME}\//;
+$opts{'facurl'} =~ s/(^|,)~\//$1$ENV{HOME}\//;
 
 if(!defined($opts{'out'}) && defined($ARGV[0])) {
     $opts{'out'} = shift;
@@ -179,8 +178,8 @@ sub get_grades {
 
 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" or die $!;
+    if((-f ($opts{'facmail'}||"")) && ! %faculty) {
+       open INS,$opts{'facmail'} or die $!;
        while($_ = <INS>) {
            chomp;
            m/"([^"]*)",([^,]*),([^,]*)/; # "
@@ -198,6 +197,27 @@ sub get_faculty_email {
     return $faculty{$name};
 }
 
+sub get_faculty_url {
+    my ($name, $url);
+    if((-f ($opts{'facurl'}||"")) && ! %facurl) {
+       open INS, $opts{'facurl'} or die $!;
+       while($_ = <INS>) {
+           chomp;
+           m/([^,]*),([^,]*)/; # "
+           ($name, $url) = ($1, $2);
+           $name =~ s/ [A-Z]\.//g;
+           $name = lc $name;
+           $name =~ s/\W//g;
+           $facurl{$name} = $url;
+       }
+    }
+    $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: <New_Years_Day\@from.sctweb>\n",
@@ -399,13 +419,13 @@ sub do_html_schedule {
            print '<span class="coursetitle">' .$row->{'title'}. '</span></td>';
            my $instructor = $row->{'instructor'};
            #$instructor =~ s/ [A-Z. ]* / /;
-           my $email = get_faculty_email($row->{'instructor'});
-           #if($email) {
-               #print '<td><a href="mailto:' . $email . '">'
-               #. $row->{'instructor'} . "</a></td>";
-           } else {
-           print "<td>" . $instructor . "</td>";
-           #}
+           my $url = get_faculty_url($row->{'instructor'});
+           if($url) {
+               print '<td><a href="' . $url . '">'
+               . $row->{'instructor'} . "</a></td>";
+           } else {
+               print "<td>" . $instructor . "</td>";
+           }
            print "<td>" . $row->{'days'} . "</td>";
            my ($a,$b) = ($row->{'begin'}, $row->{'end'});
            $b .= "AM";