From b570275c6c6b6da76ec6ba268a0c432262794cd9 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 10 Aug 2005 23:49:35 +0000 Subject: [PATCH] First attempt --- perl/sct6 | 621 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 621 insertions(+) create mode 100755 perl/sct6 diff --git a/perl/sct6 b/perl/sct6 new file mode 100755 index 0000000..fde8f7f --- /dev/null +++ b/perl/sct6 @@ -0,0 +1,621 @@ +#!/usr/bin/perl -w +# $Id$ +# -*- perl -*- vim: ft=perl sw=4 sts=4 + +# Brief usage instructions: +# Create a ~/.sct6rc that has SID=yourssn and PIN=yourpin +# You'll need to change the url below if you go anywhere but TAMUK. + +use strict; +use LWP::UserAgent; +use HTML::TableExtract; +#use Time::Local; +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 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, + "Study Day" => "4/Thu/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} . "/.sct6rc"; +if (($ARGV[0] || "") eq '-F') { + shift; + $config = shift; +} + +my $arg = ""; +$arg = shift if (defined($ARGV[0]) && $ARGV[0] =~ /^-\w$/); + +if (-r $config) { + open CONFIG, $config; + while() { + s/\#.*//; + next unless m/^([^=]*)=(.*)/; + $opts{$1}=$2; + } + close CONFIG; +} +my $domain = $opts{'domain'} || "as1.tamuk.edu:9003"; +my $url = "https://$domain/pls/PROD/"; +$url = $opts{'url'} if(defined($opts{'url'})); + +$ua = LWP::UserAgent->new; +$ua->timeout(10); +$ua->env_proxy; +$ua->cookie_jar( {} ); +$ua->get("${url}twbkwbis.P_WWWLogin") or die "$!"; +$response = $ua->post("${url}twbkwbis.P_ValLogin", { sid => $opts{SID}, PIN => $opts{PIN} }) or die "$!"; + +$response = $ua->get("${url}bwskflib.P_SelDefTerm"); # Valid terms +die $response->status_line unless $response->is_success; +my @terms = grep {s/^