X-Git-Url: http://git.tpope.net/?p=tpope-extra.git;a=blobdiff_plain;f=perl%2Fsct6;h=5295a0e162013cc46974dfbc54ab53c6eeb87520;hp=9178a710bb1cd30260537d11f12610dbdb728871;hb=3c37f39987545e322eb7ea3dd630904d13519672;hpb=062d9976c3190b14b97da61be42168cec0c848a8 diff --git a/perl/sct6 b/perl/sct6 index 9178a71..5295a0e 100755 --- a/perl/sct6 +++ b/perl/sct6 @@ -6,12 +6,16 @@ # Create a ~/.sct6rc that has SID=yourssn and PIN=yourpin # You'll need to change the url below if you go anywhere but TAMUK. +# Update: This tool now only outputs in XML. For other formats, convert +# with schedproc + use strict; -use LWP::UserAgent; -use HTML::TableExtract; 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 HTML::TableExtract; +use LWP::UserAgent; +use XML::Simple; use vars qw($ua %opts %faculty); my ($response); @@ -19,12 +23,12 @@ 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, + "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, @@ -38,9 +42,9 @@ 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) ); + 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 { @@ -71,9 +75,9 @@ $arg = shift if (defined($ARGV[0]) && $ARGV[0] =~ /^-\w$/); if (-r $config) { open CONFIG, $config; while() { - s/\#.*//; - next unless m/^([^=]*)=(.*)/; - $opts{$1}=$2; + s/\#.*//; + next unless m/^([^=]*)=(.*)/; + $opts{$1}=$2; } close CONFIG; } @@ -85,22 +89,25 @@ $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; $ua->cookie_jar( {} ); -$ua->get("${url}twbkwbis.P_WWWLogin") or die "$!"; +$response = $ua->get("${url}twbkwbis.P_WWWLogin") or die "$!"; $response = $ua->post("${url}twbkwbis.P_ValLogin", { sid => $opts{SID}, PIN => $opts{PIN} }) or die "$!"; +my %hiddenjunk; +{ + my $content = $response->content; + while($content =~ //gi) { + $hiddenjunk{$1} = $2; + } +} +$hiddenjunk{usage_btn} = "Continue"; +$response = $ua->post("${url}twbkwbis.P_FirstMenu", \%hiddenjunk); +die $response->status_line unless $response->is_success; + $response = $ua->get("${url}bwskflib.P_SelDefTerm"); # Valid terms die $response->status_line unless $response->is_success; my @terms = grep {s/^