X-Git-Url: http://git.tpope.net/?p=tpope-extra.git;a=blobdiff_plain;f=perl%2Fsctweb;h=5d82c6c786de6e11a746ae3bd9292137e049a287;hp=8c1edefb4edf63d5777843505bbe2d0f6ca4aa0a;hb=HEAD;hpb=171627372bcdbb46dc06ad8ce4e2a758abeb905b diff --git a/perl/sctweb b/perl/sctweb index 8c1edef..5d82c6c 100755 --- a/perl/sctweb +++ b/perl/sctweb @@ -6,15 +6,75 @@ # Create a ~/.sctwebrc that has SID=yourssn and PIN=yourpin # You'll need to change the url below if you go anywhere but Northwest Vista. +# Update: This tool now only outputs in XML. For other formats, convert +# with schedproc + use strict; -use LWP::UserAgent; +#use Time::Local; +use Date::Calc::Object qw(Day_of_Week Decode_Day_of_Week 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 HTML::TableExtract; -use vars qw($ua %opts); -my ($ts, $row, $response); -my $url="https://sctweb.accd.edu/ia-bin4/tsrvweb.exe?WID=W&tserve_tip_read_destroy&tserve_host_code=4&tserve_tiphost_code=0"; +use LWP::UserAgent; +use XML::Simple; +use vars qw($ua %opts %faculty); + +my ($response); + +$opts{'holidays'} = { # %{$Profiles->{'US-TX'}}, + "Martin Luther King Day" => "3/Mon/Jan", + "Good Friday" => "-2", + "Spring Break Monday" => \&Spring_Break, + "Spring Break Tuesday" => \&Spring_Break, + "Spring Break Wednesday" => \&Spring_Break, + "Spring Break Thursday" => \&Spring_Break, + "Spring Break Friday" => \&Spring_Break, + "Spring Break Saturday" => \&Spring_Break, + "Fiesta Holiday" => "4/Fri/Apr", + "Memorial Day" => "5/Mon/May", + "Independence Day" => \&US_Independence, + "Labor Day" => \&US_Labor, + "Columbus Day" => "2/Mon/Oct", + "Thanksgiving Day" => "4/Thu/Nov", + "Thanksgiving Friday" => \&Thanksgiving_Friday, +}; + +sub Spring_Break { + my($year,$label) = @_; + $label =~ s/^Spring Break //; + return( Add_Delta_Days( + Nth_Weekday_of_Month_Year($year,1,1,1), + 7*(11-1) # This is for the 11th Monday of the year + +Decode_Day_of_Week($label)-1) ); +} + +sub Thanksgiving_Friday { + my($year,$label) = @_; + return( Add_Delta_Days(Nth_Weekday_of_Month_Year($year,11,4,4), 1) ); +} +sub US_Independence # Fourth of July +{ + my($year,$label) = @_; + return( &Date::Calendar::Profiles::Nearest_Workday($year,7,4) ); +} +sub US_Labor # First Monday after the first Sunday in September +{ + my($year,$label) = @_; + return( Add_Delta_Days( + Nth_Weekday_of_Month_Year($year,9,7,1), +1) ); +} + +my $config = $ENV{HOME} . "/.sctwebrc"; +if ($ARGV[0] eq '-F') { + shift; + $config = shift; +} + +my $arg = ""; +$arg = shift if (defined($ARGV[0]) && $ARGV[0] =~ /^-\w$/); -if (-r $ENV{HOME} . "/.sctwebrc") { - open CONFIG, $ENV{HOME} . "/.sctwebrc"; +if (-r $config) { + open CONFIG, $config; while() { s/\#.*//; next unless m/^([^=]*)=(.*)/; @@ -22,6 +82,9 @@ if (-r $ENV{HOME} . "/.sctwebrc") { } close CONFIG; } +my $domain = $opts{'domain'} || "sctweb.accd.edu"; +my $url = "https://$domain/ia-bin4/tsrvweb.exe?WID=W&tserve_tip_read_destroy&tserve_host_code=4&tserve_tiphost_code=0"; +$url = $opts{'url'} if(defined($opts{'url'})); $ua = LWP::UserAgent->new; $ua->timeout(10); @@ -32,16 +95,76 @@ $response = $ua->post("$url&tserve_trans_config=astulog.cfg", { tserve_tip_write $response = $ua->get("$url&tserve_tip_write=||WID|SID|PIN|Term&tserve_trans_config=" . ("regterm.cfg"||"rgrdterm.cfg")); # Valid terms die $response->status_line unless $response->is_success; -my @terms = grep {s/^