From: Tim Pope Date: Sat, 20 Aug 2005 07:34:54 +0000 (+0000) Subject: Faculty URL X-Git-Url: http://git.tpope.net/?p=tpope-extra.git;a=commitdiff_plain;h=83030841efa4d14402311088179c7e3338e6980c Faculty URL --- diff --git a/perl/schedproc b/perl/schedproc index dab1f18..8c45f83 100755 --- a/perl/schedproc +++ b/perl/schedproc @@ -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($_ = ) { 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($_ = ) { + 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: \n", @@ -399,13 +419,13 @@ sub do_html_schedule { print '' .$row->{'title'}. ''; my $instructor = $row->{'instructor'}; #$instructor =~ s/ [A-Z. ]* / /; - my $email = get_faculty_email($row->{'instructor'}); - #if($email) { - #print '' - #. $row->{'instructor'} . ""; - # } else { - print "" . $instructor . ""; - #} + my $url = get_faculty_url($row->{'instructor'}); + if($url) { + print '' + . $row->{'instructor'} . ""; + } else { + print "" . $instructor . ""; + } print "" . $row->{'days'} . ""; my ($a,$b) = ($row->{'begin'}, $row->{'end'}); $b .= "AM";