From: Tim Pope Date: Mon, 12 Dec 2005 03:07:07 +0000 (+0000) Subject: Grade support X-Git-Url: http://git.tpope.net/?p=tpope-extra.git;a=commitdiff_plain;h=0e022804222e7feacce5095a149843ead4a0f9ef Grade support --- diff --git a/perl/sct6 b/perl/sct6 index cb3fe0b..3682c39 100755 --- a/perl/sct6 +++ b/perl/sct6 @@ -23,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, @@ -42,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 { @@ -75,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; } @@ -106,19 +106,19 @@ sub next_class { 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; } @@ -137,16 +137,16 @@ sub off_for_holidays { 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"; } @@ -161,19 +161,19 @@ sub off_for_exams { 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 ? () : ""; } @@ -207,21 +207,21 @@ sub capitalize { 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; } @@ -233,60 +233,60 @@ sub get_schedule { 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/.*]*>(.* - .... \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/.*]*>(.* - .... \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; } @@ -296,16 +296,67 @@ sub do_xml_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 "\n\n"; +#} + sub do_xml_grades { - print "\n\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/^