$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,
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 {
if (-r $config) {
open CONFIG, $config;
while(<CONFIG>) {
- s/\#.*//;
- next unless m/^([^=]*)=(.*)/;
- $opts{$1}=$2;
+ s/\#.*//;
+ next unless m/^([^=]*)=(.*)/;
+ $opts{$1}=$2;
}
close CONFIG;
}
$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 =~ /<input type="hidden" name="(.*?)" value="(.*?)">/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/^<option value="([^"]*)">.*/$1/i} (split( /\r?\n/, $response->content)); # "
my $today = Date::Calc->new(Date::Calc->localtime(time+3600*6)->date);
my @days=();
foreach(split(" ",$class{'days'})) {
- push @days, Decode_Day_of_Week($_);
+ push @days, Decode_Day_of_Week($_);
}
my @off = @{$class{'off'}};
for($today = ($today > $firstday ? $today : $firstday); $today < $lastday; $today++) {
- next unless(grep($_ == Day_of_Week($today->date), @days));
- next if(grep($_ == $today, @off));
- return $today;
+ next unless(grep($_ == Day_of_Week($today->date), @days));
+ next if(grep($_ == $today, @off));
+ return $today;
}
$today = Date::Calc->new(Date::Calc->gmtime->date);
for($today = ($today < $lastday ? $today : $lastday); $today > $firstday; $today--) {
- next unless(grep($_ == Day_of_Week($today->date), @days));
- next if(grep($_ == $today, @off));
- return $today;
+ next unless(grep($_ == Day_of_Week($today->date), @days));
+ next if(grep($_ == $today, @off));
+ return $today;
}
return undef;
}
my @holidays=();
my @days=();
foreach(split(" ",$d)) {
- $days[Decode_Day_of_Week($_)] = 1;
+ $days[Decode_Day_of_Week($_)] = 1;
}
foreach ($year->search("")) {
- my $good=1;
- #foreach my $x ($year->labels($_)) {
- # $good=0 if ($x =~ /Veteran/ or $x =~ /President/);
- #}
- next unless ($year->is_full($_) && $_>=$firstday && $_<=$lastday);
- push @holidays, $_
- if (defined($days[Day_of_Week($_->date)]) && $good > 0);
+ my $good=1;
+ #foreach my $x ($year->labels($_)) {
+ # $good=0 if ($x =~ /Veteran/ or $x =~ /President/);
+ #}
+ next unless ($year->is_full($_) && $_>=$firstday && $_<=$lastday);
+ push @holidays, $_
+ if (defined($days[Day_of_Week($_->date)]) && $good > 0);
}
return wantarray ? @holidays : "@holidays";
}
my $ending ="(06:30-07:45|09:30-10:45|12:30-13:45|15:30-16:45|18:30-19:45|19:00-20:15)";
my $days = join(" ",map {Decode_Day_of_Week($_)} split(/ /, $class{'days'}));
if($days eq "1 3") {
- if($time =~ /$beginning/) {
- return $lastday-4;
- } elsif($time =~ /$ending/) {
- return $lastday-6;
- }
+ if($time =~ /$beginning/) {
+ return $lastday-4;
+ } elsif($time =~ /$ending/) {
+ return $lastday-6;
+ }
} elsif($days eq "2 4") {
- if($time =~ /$beginning/) {
- return $lastday-3;
- } elsif($time =~ /$ending/) {
- return $lastday-5;
- }
+ if($time =~ /$beginning/) {
+ return $lastday-3;
+ } elsif($time =~ /$ending/) {
+ return $lastday-5;
+ }
} elsif($days eq "5") {
- return $lastday-2;
+ return $lastday-2;
}
return wantarray ? () : "";
}
sub get_schedule_terms {
my (@sterms, @a);
- @a=('10','20','30','40'); # Fall, Spring, Summer I, Summer II
- # Last 3 are currently guesses
+ @a=('10','20','30','40'); # Fall, Spring, Summer I, Summer II
+ # Last 3 are currently guesses
my @localtime=localtime();
if ($localtime[4]<3) { # Through Mar 31
- @sterms=((1900+$localtime[5]).$a[1]);
+ @sterms=((1900+$localtime[5]).$a[1]);
} elsif ($localtime[4]<5) { # Through May 31
- @sterms=((1900+$localtime[5]).$a[1],(1900+$localtime[5]).$a[2]);
+ @sterms=((1900+$localtime[5]).$a[1],(1900+$localtime[5]).$a[2]);
} elsif ($localtime[4]<7) { # through July 31
- @sterms=((1900+$localtime[5]).$a[2],(1900+$localtime[5]).$a[3]);
+ @sterms=((1900+$localtime[5]).$a[2],(1900+$localtime[5]).$a[3]);
} elsif ($localtime[4]<8) { # through Aug 31
- @sterms=((1900+$localtime[5]).$a[3],(1901+$localtime[5]).$a[0]);
+ @sterms=((1900+$localtime[5]).$a[3],(1901+$localtime[5]).$a[0]);
} elsif ($localtime[4]<10) { # through Oct 31
- @sterms=((1901+$localtime[5]).$a[0]);
+ @sterms=((1901+$localtime[5]).$a[0]);
} else {
- @sterms=((1901+$localtime[5]).$a[0],(1901+$localtime[5]).$a[1]);
+ @sterms=((1901+$localtime[5]).$a[0],(1901+$localtime[5]).$a[1]);
}
return @sterms;
}
my (@schedule, @terms, $classid, $title, $begin, $end, $times, $days, $session);
@terms = get_schedule_terms();
foreach (@_ ? @_ : @terms) {
- $response = $ua->get("${url}bwskfshd.P_CrseSchdDetl?term_in=$_" );
- die $response->status_line unless $response->is_success;
- $te->parse($response->content);
- foreach my $l (split (/\n/, $response->content)) {
- next unless $l =~ s/.*<CAPTION class=[^>]*>(.* - .... \d\d\d\d \d\d\d)<\/caption>.*/$1/i;
- push @class, $l;
- }
+ $response = $ua->get("${url}bwskfshd.P_CrseSchdDetl?term_in=$_" );
+ die $response->status_line unless $response->is_success;
+ $te->parse($response->content);
+ foreach my $l (split (/\n/, $response->content)) {
+ next unless $l =~ s/.*<CAPTION class=[^>]*>(.* - .... \d\d\d\d \d\d\d)<\/caption>.*/$1/i;
+ push @class, $l;
+ }
}
foreach my $ts ($te->table_states) {
- foreach my $row ($ts->rows) {
- #map { s/\xa0//g; $_} @$row;
- #$row->[0] =~ s/.*launchWebCT\("([^"]*)"\).*/$1/s;
- #$row->[0] =~ s/(.*) ?<[Bb][Rr][^>]*>(.*)/capitalize($2)/eg;
- $classid = (shift @class);
- $title = $classid;
- $classid =~ s/.* - //;
- $classid =~ s/ /-/g;
- $title =~ s/ - .*//;
- $row->[6] =~ s/\b([A-Z]r?)$/$1./;
- $row->[6] = capitalize($row->[6]);
- $row->[6] =~ s/ *\([A-Z]\)//;
- $row->[1] =~ s/ ?([ap])m/\u$1M/g;
- $row->[1] =~ s/ - /-/;
- ($begin, $end) = split(/ ?- ?/, $row->[1]);
- $begin =~ s/^(\d):/0$1:/;
- $end =~ s/^(\d):/0$1:/;
- if (($begin=~/PM$/ && $begin!~/^12/)||($begin=~/^12:..AM/)) {
- $begin =~ s/^(\d?\d)/($1+12)%24/e;
- }
- if (($end=~/PM$/ && $end!~/^12/)||($end=~/^12:..AM/)) {
- $end =~ s/^(\d?\d)/($1+12)%24/e;
- }
- $begin =~ s/ ?[AP]M//;
- $end =~ s/ ?[AP]M//;
- $row->[4] =~ s/([A-Za-z]{3,9})/(Decode_Month($1)<10?"0":"").Decode_Month($1)/eg;
- $row->[4] =~ s/(\d\d?) (\d\d), (\d\d\d\d)/$3$1$2/g;
- $row->[4] =~ s/ - /-/;
- $row->[3] =~ s/(ON|MAIN) CAMPUS\n|Palo Alto Building \d* //ig;
- $row->[3] =~ s/\n/ /g;
- my %class = (
- id => $classid,
- title => capitalize($title),
- instructor => $row->[6],
- days => $row->[2],
- #'time' => $row->[1],
- begin => $begin,
- end => $end || undef,
- duration => $row->[4],
- location => $row->[3],
- );
- my @off = ( map { "$_"; } (off_for_holidays(%class), off_for_exams(%class)));
- $class{'off'} = [ @off ] if (@off);
- push @schedule, \%class;
- }
+ foreach my $row ($ts->rows) {
+ #map { s/\xa0//g; $_} @$row;
+ #$row->[0] =~ s/.*launchWebCT\("([^"]*)"\).*/$1/s;
+ #$row->[0] =~ s/(.*) ?<[Bb][Rr][^>]*>(.*)/capitalize($2)/eg;
+ $classid = (shift @class);
+ $title = $classid;
+ $classid =~ s/.* - //;
+ $classid =~ s/ /-/g;
+ $title =~ s/ - .*//;
+ $row->[6] =~ s/\b([A-Z]r?)$/$1./;
+ $row->[6] = capitalize($row->[6]);
+ $row->[6] =~ s/ *\([A-Z]\)//;
+ $row->[1] =~ s/ ?([ap])m/\u$1M/g;
+ $row->[1] =~ s/ - /-/;
+ ($begin, $end) = split(/ ?- ?/, $row->[1]);
+ $begin =~ s/^(\d):/0$1:/;
+ $end =~ s/^(\d):/0$1:/;
+ if (($begin=~/PM$/ && $begin!~/^12/)||($begin=~/^12:..AM/)) {
+ $begin =~ s/^(\d?\d)/($1+12)%24/e;
+ }
+ if (($end=~/PM$/ && $end!~/^12/)||($end=~/^12:..AM/)) {
+ $end =~ s/^(\d?\d)/($1+12)%24/e;
+ }
+ $begin =~ s/ ?[AP]M//;
+ $end =~ s/ ?[AP]M//;
+ $row->[4] =~ s/([A-Za-z]{3,9})/(Decode_Month($1)<10?"0":"").Decode_Month($1)/eg;
+ $row->[4] =~ s/(\d\d?) (\d\d), (\d\d\d\d)/$3$1$2/g;
+ $row->[4] =~ s/ - /-/;
+ $row->[3] =~ s/(ON|MAIN) CAMPUS\n|Palo Alto Building \d* //ig;
+ $row->[3] =~ s/\n/ /g;
+ my %class = (
+ id => $classid,
+ title => capitalize($title),
+ instructor => $row->[6],
+ days => $row->[2],
+ #'time' => $row->[1],
+ begin => $begin,
+ end => $end || undef,
+ duration => $row->[4],
+ location => $row->[3],
+ );
+ my @off = ( map { "$_"; } (off_for_holidays(%class), off_for_exams(%class)));
+ $class{'off'} = [ @off ] if (@off);
+ push @schedule, \%class;
+ }
}
return @schedule;
}
my $schedule = { class => [ get_schedule(@_) ] };
my $xml = XMLout($schedule, NoAttr => 1, RootName => 'schedule');
if($file) {
- open FH, ">$file";
- print FH $xml;
- close FH;
+ open FH, ">$file";
+ print FH $xml;
+ close FH;
} else {
- print $xml;
+ print $xml;
}
}
+#sub do_xml_grades {
+# print "<grades>\n</grades>\n";
+#}
+
sub do_xml_grades {
- print "<grades>\n</grades>\n";
+ #my @readheaders = ("Subject", "Course", "Section", "Course Title", "Final Grade", "Attempted", "Earned", "GPA Hours", "Quality Points");
+ my @readheaders = ("Subject", "Course", "Section", "CTitle", "Final Grade", "Attempted", "Earned", "GPA Hours", "Quality Points");
+ my ($row, $lastrow);
+ my $te = new HTML::TableExtract( headers => [ @readheaders ] );
+ my $response = $ua->get("$url/bwskogrd.P_ViewTermGrde"); # Valid grading terms
+ die $response->status_line unless $response->is_success;
+ #my @terms = reverse grep {s/^<option value="([^"]*)">.*/$1/} (split( /\r\n/, $response->content));
+ my @grades = ();
+ my @terms = ();
+ my $year = Date::Calc->localtime->year;
+ for(my $y=$year-3;$y<=$year+1;$y++) { push @terms, ($y.10,$y.20,$y.30,$y.40); }
+ foreach(@_ ? @_ : @terms) {
+ $response = $ua->get("$url/bwskogrd.P_ViewGrde?term_in=".($_) );
+ die $response->status_line unless $response->is_success;
+ my $content = $response->content;
+ $content =~ s/Course Title/CTitle/g;
+ $te->parse($content);
+ }
+ foreach my $ts ($te->table_states) {
+ foreach my $row ($ts->rows) {
+ map { s/^\s+//; s/\xa0|\r//g; s/\n/<br \/>/g; $_} @$row;
+ $row->[3] = capitalize($row->[3]);
+ $row->[3] =~ s/&/&/g;
+ #$row->[0] =~ s/Cumulative through/Cumulative: through/;
+ #$row->[0] =~ s/Cumulative:(.*) (\d{4}) (.*)/Cumulative:$1 $3 $2/;
+ $lastrow=$row;
+ next if $row->[0] =~ /:|Current Term/;
+ push @grades, {
+ id => $row->[0]."-".$row->[1]."-".$row->[2],
+ title => $row->[3],
+ grade => $row->[4],
+ attempted => $row->[5],
+ earned => $row->[6],
+ hours => $row->[7],
+ points => $row->[8]
+ };
+ }
+ }
+ $lastrow->[0] =~ s/Cumulative:? *through *//i if($lastrow->[0]);
+ my $cumulative = { term => capitalize($lastrow->[0]),
+ gpa => $lastrow->[6],
+ earned => $lastrow->[3],
+ hours => $lastrow->[4],
+ points => $lastrow->[5]
+ };
+ my $xml = XMLout({class => [@grades], cumulative => []}, NoAttr => 1, RootName => 'grades');
+ print $xml;
+ return;
}
sub do_transcripts {
do_xml_grades(@ARGV);
} elsif ($arg eq "-t") {
do_transcripts;
-} elsif ($arg eq "-x" || $arg = "-s" || 1) {
+} elsif ($arg eq "-x" || $arg eq "-s" || 1) {
do_xml_schedule(@ARGV);
}