+ #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;
+ 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;