3 # -*- perl -*- vim: ft=perl sw=4 sts=4
5 # Brief usage instructions:
6 # Create a ~/.sct6rc that has SID=yourssn and PIN=yourpin
7 # You'll need to change the url below if you go anywhere but TAMUK.
11 use HTML::TableExtract;
12 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);
13 use Date::Calendar::Profiles qw($Profiles);
14 use Date::Calendar::Year;
15 use vars qw($ua %opts %faculty);
19 $opts{'holidays'} = { # %{$Profiles->{'US-TX'}},
20 "Martin Luther King Day" => "3/Mon/Jan",
21 "Good Friday" => "-2",
22 "Spring Break Monday" => \&Spring_Break,
23 "Spring Break Tuesday" => \&Spring_Break,
24 "Spring Break Wednesday" => \&Spring_Break,
25 "Spring Break Thursday" => \&Spring_Break,
26 "Spring Break Friday" => \&Spring_Break,
27 "Spring Break Saturday" => \&Spring_Break,
28 "Study Day" => "4/Thu/Apr", # ?
29 "Memorial Day" => "5/Mon/May",
30 "Independence Day" => \&US_Independence,
31 "Labor Day" => \&US_Labor,
32 #"Columbus Day" => "2/Mon/Oct",
33 "Thanksgiving Day" => "4/Thu/Nov",
34 "Thanksgiving Friday" => \&Thanksgiving_Friday,
38 my($year,$label) = @_;
39 $label =~ s/^Spring Break //;
40 return( Add_Delta_Days(
41 Nth_Weekday_of_Month_Year($year,1,1,1),
42 7*(11-1) # This is for the 11th Monday of the year
43 +Decode_Day_of_Week($label)-1) );
46 sub Thanksgiving_Friday {
47 my($year,$label) = @_;
48 return( Add_Delta_Days(Nth_Weekday_of_Month_Year($year,11,4,4), 1) );
50 sub US_Independence # Fourth of July
52 my($year,$label) = @_;
53 return( &Date::Calendar::Profiles::Nearest_Workday($year,7,4) );
55 sub US_Labor # First Monday after the first Sunday in September
57 my($year,$label) = @_;
58 return( Add_Delta_Days(
59 Nth_Weekday_of_Month_Year($year,9,7,1), +1) );
62 my $config = $ENV{HOME} . "/.sct6rc";
63 if (($ARGV[0] || "") eq '-F') {
69 $arg = shift if (defined($ARGV[0]) && $ARGV[0] =~ /^-\w$/);
75 next unless m/^([^=]*)=(.*)/;
80 my $domain = $opts{'domain'} || "as1.tamuk.edu:9003";
81 my $url = "https://$domain/pls/PROD/";
82 $url = $opts{'url'} if(defined($opts{'url'}));
84 $ua = LWP::UserAgent->new;
87 $ua->cookie_jar( {} );
88 $ua->get("${url}twbkwbis.P_WWWLogin") or die "$!";
89 $response = $ua->post("${url}twbkwbis.P_ValLogin", { sid => $opts{SID}, PIN => $opts{PIN} }) or die "$!";
91 $response = $ua->get("${url}bwskflib.P_SelDefTerm"); # Valid terms
92 die $response->status_line unless $response->is_success;
93 my @terms = grep {s/^<option value="([^"]*)">.*/$1/i} (split( /\r?\n/, $response->content)); # "
94 die "Site down. Try again later.\n" unless (@terms);
97 my ($section, $number) = split("-", shift);
99 foreach (split //, $section) {$id=26*$id+(ord($_)-1)%32;}
100 $id=10000*$id+$number;
106 $class{'duration'} =~ /(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)/;
107 my $days = Delta_Days($1,$2,$3,$4,$5,$6);
108 my $firstday = Date::Calc->new($1,$2,$3);
109 my $lastday = Date::Calc->new($4,$5,$6);
110 my $today = Date::Calc->new(Date::Calc->localtime(time+3600*6)->date);
112 foreach(split(" ",$class{'days'})) {
113 push @days, Decode_Day_of_Week($_);
115 my @off = (off_for_holidays(%class),off_for_exams(%class));
116 for($today = ($today > $firstday ? $today : $firstday); $today < $lastday; $today++) {
117 next unless(grep($_ == Day_of_Week($today->date), @days));
118 next if(grep($_ == $today, @off));
121 $today = Date::Calc->new(Date::Calc->gmtime->date);
122 for($today = ($today < $lastday ? $today : $lastday); $today > $firstday; $today--) {
123 next unless(grep($_ == Day_of_Week($today->date), @days));
124 next if(grep($_ == $today, @off));
130 sub off_for_holidays {
132 $class{'duration'} =~ /(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)/;
133 my $days = Delta_Days($1,$2,$3,$4,$5,$6);
134 my $firstday = Date::Calc->new($1,$2,$3);
135 my $lastday = Date::Calc->new($4,$5,$6);
136 my $year = Date::Calendar::Year->new($1, $opts{'holidays'});
139 foreach(split(" ",$class{days})) {
140 $days[Decode_Day_of_Week($_)] = 1;
142 foreach ($year->search("")) {
144 #foreach my $x ($year->labels($_)) {
145 # $good=0 if ($x =~ /Veteran/ or $x =~ /President/);
147 next unless ($year->is_full($_) && $_>=$firstday && $_<=$lastday);
149 if (defined($days[Day_of_Week($_->date)]) && $good > 0);
151 return wantarray ? @holidays : "@holidays";
156 my $time = $class{'begin'} . "-" . $class{'end'};
157 $class{'duration'} =~ /\d{8}-(\d\d\d\d)(\d\d)(\d\d)/;
158 my $lastday = Date::Calc->new($1,$2,$3);
159 return wantarray ? () : undef unless (Day_of_Week($lastday->date) == 7);
160 my $beginning="(08:00-09:15|11:00-12:15|14:00-15:15|17:00-18:15|17:30-18:45|20:00-21:15|20:30-21:45)";
161 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)";
162 my $days = join(" ",map {Decode_Day_of_Week($_)} split(/ /, $class{'days'}));
164 if($time =~ /$beginning/) {
166 } elsif($time =~ /$ending/) {
169 } elsif($days eq "2 4") {
170 if($time =~ /$beginning/) {
172 } elsif($time =~ /$ending/) {
175 } elsif($days eq "5") {
178 return wantarray ? () : "";
182 local $_ = shift || "";
184 s/\b([A-Z])([A-Z]*)\b/$1\L$2/g;
185 s/\b(I)(i*)\b/$1\U$2/g;
187 s/ (And|For|Of|Or|The|To|With) / \l$1 /g;
188 s/\b(Mc)([a-z])/$1\u$2/g;
190 s/\b(Tcp\/Ip|Pc)\b/\U$&/g;
191 s/\bThru\b/Through/g;
192 s/\bAcct\b/Accounting/g;
193 s/\bAmer\b/American/g;
194 s/\bChem\b/Chemistry/g;
195 s/\bComp\b/Composition/g;
198 s/\bIntro\b/Introduction/g;
199 s/\bPrgm\b/Programming/g;
200 s/\bOp Sys\b/Operating System/g;
201 #s/\bGovt\b/Government/g;
202 s/\bLit\b/Literature/g;
203 s/\bPrin\b/Principles/g;
204 s/\bBus\b/Business/g;
208 sub get_schedule_terms {
210 @a=('10','20','30','40'); # Fall, Spring, Summer I, Summer II
211 # Last 3 are currently guesses
212 my @localtime=localtime();
213 if ($localtime[4]<3) { # Through Mar 31
214 @sterms=((1900+$localtime[5]).$a[1]);
215 } elsif ($localtime[4]<5) { # Through May 31
216 @sterms=((1900+$localtime[5]).$a[1],(1900+$localtime[5]).$a[2]);
217 } elsif ($localtime[4]<7) { # through July 31
218 @sterms=((1900+$localtime[5]).$a[2],(1900+$localtime[5]).$a[3]);
219 } elsif ($localtime[4]<8) { # through Aug 31
220 @sterms=((1900+$localtime[5]).$a[3],(1901+$localtime[5]).$a[0]);
221 } elsif ($localtime[4]<10) { # through Oct 31
222 @sterms=((1901+$localtime[5]).$a[0]);
224 @sterms=((1901+$localtime[5]).$a[0],(1901+$localtime[5]).$a[1]);
230 my @readheaders = ("Type", "Time", "Days", "Where", "Date Range", "Schedule Type", "Instructors");
232 my $te = new HTML::TableExtract( headers => [ @readheaders ] );
233 my (@schedule, @terms, $classid, $title, $begin, $end, $times, $days, $session);
234 @terms = get_schedule_terms();
235 foreach (@_ ? @_ : @terms) {
236 $response = $ua->get("${url}bwskfshd.P_CrseSchdDetl?term_in=$_" );
237 die $response->status_line unless $response->is_success;
238 $te->parse($response->content);
239 foreach my $l (split (/\n/, $response->content)) {
240 next unless $l =~ s/.*<CAPTION class=[^>]*>(.* - .... \d\d\d\d \d\d\d)<\/caption>.*/$1/i;
244 foreach my $ts ($te->table_states) {
245 foreach my $row ($ts->rows) {
246 #map { s/\xa0//g; $_} @$row;
247 #$row->[0] =~ s/.*launchWebCT\("([^"]*)"\).*/$1/s;
248 #$row->[0] =~ s/(.*) ?<[Bb][Rr][^>]*>(.*)/capitalize($2)/eg;
249 $classid = (shift @class);
251 $classid =~ s/.* - //;
254 $row->[6] = capitalize($row->[6]);
255 $row->[6] =~ s/([A-Z]r?)$/$1./;
256 $row->[6] =~ s/ *\([A-Z]\)//;
257 $row->[1] =~ s/ ?([ap])m/\u$1M/g;
258 $row->[1] =~ s/ - /-/;
259 ($begin, $end) = split(/ ?- ?/, $row->[1]);
260 $begin =~ s/^(\d):/0$1:/;
261 $end =~ s/^(\d):/0$1:/;
262 if ($begin =~ /pm$/i && $begin !~ /^12/) {
263 $begin =~ s/^(\d?\d)/$1+12/e;
265 if ($end =~ /pm$/i && $end !~ /^12/) {
266 $end =~ s/^(\d?\d)/$1+12/e;
268 $begin =~ s/ ?[AP]M//;
270 $row->[4] =~ s/([A-Za-z]{3,9})/(Decode_Month($1)<10?"0":"").Decode_Month($1)/eg;
271 $row->[4] =~ s/(\d\d?) (\d\d), (\d\d\d\d)/$3$1$2/g;
272 $row->[4] =~ s/ - /\n/;
273 $row->[3] =~ s/(ON|MAIN) CAMPUS\n|Palo Alto Building \d* //ig;
274 $row->[3] =~ s/\n/ /g;
278 #session => $row->[1],
279 instructor => $row->[6],
280 #credits => $row->[3],
281 #callnumber => $row->[4],
282 #gradetype => $row->[5],
286 end => $end || undef,
287 duration => $row->[4],
288 location => $row->[3],
289 #message => $row->[10],
296 sub get_faculty_email {
297 my ($name, $school, $email);
298 if((-f $ENV{'HOME'} . "/public_html/faculty.csv") && ! %faculty) {
299 open INS, $ENV{'HOME'} . "/public_html/faculty.csv";
302 m/"([^"]*)",([^,]*),([^,]*)/; # "
303 ($name, $email, $school) = ($1, $2, $3);
304 $name =~ s/^([^,]*), ([^,]*)(.*)$/$2 $1$3/;
305 $name =~ s/ [A-Z]\.//g;
308 $faculty{$name} = $email;
312 $name =~ s/ [A-Z]r?\.//g;
315 return $faculty{$name};
320 "X-SC-Subject: New Years Day\nX-SC-Category: Holiday\nX-SC-Cond: 1 Jan\nX-SC-Duration: 00010101-\nX-SC-Record-Id: <New_Years_Day\@from.sctweb>\n",
321 "X-SC-Subject: Martin Luther King, Jr. Day\nX-SC-Category: Holiday\nX-SC-Cond: 3rd Mon Jan\nX-SC-Duration: 19870119-\nX-SC-Record-Id: <Martin_Luther_King_Jr_Day\@from.sctweb>\n",
322 "X-SC-Subject: Presidents Day\nX-SC-Category: Holiday\nX-SC-Cond: 3rd Mon Feb\nX-SC-Duration: 19710515-\nX-SC-Record-Id: <Presidents_Day\@from.sctweb>\n",
323 "X-SC-Subject: Memorial Day\nX-SC-Category: Holiday\nX-SC-Cond: Last Mon May\nX-SC-Duration: 19710531-\nX-SC-Record-Id: <Memorial_Day\@from.sctweb>\n",
324 "X-SC-Subject: Independence Day\nX-SC-Category: Holiday\nX-SC-Cond: 4 Jul\nX-SC-Duration: 17760704-\nX-SC-Record-Id: <Independence_Day\@from.sctweb>\n",
325 "X-SC-Subject: Labor Day\nX-SC-Category: Holiday\nX-SC-Cond: 1st Mon Sep\nX-SC-Duration: 18840901-\nX-SC-Record-Id: <Labor_Day\@from.sctweb>\n",
326 "X-SC-Subject: Columbus Day\nX-SC-Category: Holiday\nX-SC-Cond: 2nd Mon Oct\nX-SC-Duration: 19711011-\nX-SC-Record-Id: <Columbus_Day\@from.sctweb>\n",
327 "X-SC-Subject: Veterans Day\nX-SC-Category: Holiday\nX-SC-Cond: 11 Nov\nX-SC-Duration: 19261111-\nX-SC-Record-Id: <Veterans_Day\@from.sctweb>\n",
328 "X-SC-Subject: Thanksgiving\nX-SC-Category: Holiday\nX-SC-Cond: 4th Thu Nov\nX-SC-Duration: 14921122-\nX-SC-Record-Id: <Thanksgiving\@from.sctweb>\n",
329 "X-SC-Subject: Christmas\nX-SC-Category: Holiday\nX-SC-Cond: 25 Dec\nX-SC-Duration: 00011225-\nX-SC-Record-Id: <Christmas\@from.sctweb>\n",
333 sub do_mhc_schedule {
335 my %days = (M => "Mon", T => "Tue", W => "Wed", R => "Thu", F => "Fri", S => "Sat", U => "SU");
336 my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
337 my ($file, $current, @mhc, @schedule);
338 $file = shift unless (!defined $_[0] or $_[0] =~ /^\d/);
339 @schedule = get_schedule(@_);
340 @mhc = get_mhc_header;
341 if(defined($file) && (-d $file)) {
344 $_ =~ s/X-SC-Subject: ([^\n]*)/X-SC-Subject: $1\nSubject: $1/;
345 $_ =~ s/X-SC-Category: ([^\n]*)/X-SC-Category: $1\nFrom: $1/;
346 $_ =~ s/X-SC-Duration: (\d\d\d\d)(\d\d)(\d\d)-/"X-SC-Duration: $1$2$3-\nDate: $3 " . $mon[$2-1] . " 1970 12:00:00 +0000"/e;
351 foreach my $row (@schedule) {
352 map {s/\n/-/g if defined; $_} %$row;
353 my $id=generate_id($row->{'id'});
354 $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
355 $row->{'days'} =~ s/^ //;
356 #$row->{'duration'} =~ s/(\d\d)-(\d\d)-(\d\d)/20$3$1$2/g;
357 my @day = map { "!" . $_ } (off_for_holidays(%$row),off_for_exams(%$row));
360 $current .= "X-SC-Subject: " . $row->{'title'} . "\n";
361 $current .= "X-SC-Location: " . $row->{'location'} . "\n";
362 $current .= "X-SC-Category: School\n";
363 $current .= "X-SC-Cond: " . $row->{'days'} . "\n";
364 $current .= "X-SC-Time: ".$row->{'begin'}."-".$row->{'end'}."\n";
365 $current .= "X-SC-Duration: " . $row->{'duration'} . "\n";
366 $current .= "X-SC-Day: @day\n" if(exists $day[0]);
367 $current .= "X-SC-Alarm: 15 minutes\n";
368 $current .= "X-SC-Record-Id: <".$row->{'id'}."\@from.sctweb>\n";
369 if(defined($file) && (-d $file)) {
370 $row->{'instructor'} =~ s/^([^,]*), ([^,]*)(.*)/$2 $1$3/;
371 my $email = get_faculty_email $row->{'instructor'};
372 $row->{'instructor'} = '"' . $row->{'instructor'} . '" <'. ($email || ($1 || "unknown") . "\@from.sctweb") . ">";
373 $row->{'duration'} =~ /^(\d\d\d\d)(\d\d)(\d\d)-\d{8}$/;
374 $row->{'begin'} =~ /^(\d\d):(\d\d)$/;
375 my $next = next_class(%$row);
376 my @date = Gmtime(Mktime($next->date,$1,$2,0));
377 $current .= sprintf "Date: %s, %2d %s %4d %02d:%02d:00 +0000\n", Day_of_Week_Abbreviation($date[7]), $date[2], $mon[$date[1]-1], $date[0], $date[3], $date[4], $date[5];
378 $current .= "Subject: " . $row->{'title'} . "\n";
379 $current .= "From: " . $row->{'instructor'} . "\n";
384 if(defined($file) && (-d $file)) {
386 foreach my $name (<$file/[1-9]*>) {
387 next unless $name =~ /^$file\/[1-9][0-9]*$/;
392 unlink $name if /^X-SC-Record-Id: <.*\@from.sctweb>/;
398 open FH, ">$file/$i" or die $!;
403 open(STDOUT, ">" . $file) if(defined($file));
404 print "# MHC school schedule\n# Autogenerated by sctweb ".localtime()."\n\n";
405 print join("\n", @mhc);
409 sub do_csv_schedule {
411 my %days = (M => "Mon", T => "Tue", W => "Wed", R => "Thu", F => "Fri", S => "Sat", U => "SU");
412 my @mon = qw(Jan. Feb. Mar. Apr. May June July Aug. Sept. Oct. Nov. Dec.);
413 my (@terms, $file, $current, @mhc, @schedule);
414 $file = shift unless (!defined $_[0] or $_[0] =~ /^\d/);
415 @schedule = get_schedule(@_);
416 open(STDOUT, ">" . $file) if(defined($file));
417 foreach my $row (@schedule) {
418 map {s/\n/-/g if defined; $_} %$row;
419 my $id=generate_id($row->{'id'});
420 $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
421 $row->{'days'} =~ s/^ //;
422 $row->{'instructor'} =~ s/^([^,]*), ([^,]*)/$2 $1/;
423 my $next = next_class(%$row);
426 $current .= $row->{'id'} . ",";
427 $current .= $row->{'title'} . ",";
428 $current .= '"' . $row->{'instructor'} . '",';
429 $next =~ /^(\d\d\d\d)(\d\d)(\d\d)$/;
430 $current .= $1 . "-". $2 ."-" . $3 . "\n";
435 sub do_vcalendar_schedule {
437 my %days = (M => "MO", T => "TU", W => "WE", R => "TH", F => "FR", S => "SA", U => "SU");
438 my $file = shift if (defined $_[0] and $_[0] !~ /^\d/);
439 my @schedule = get_schedule(@_);
440 open(STDOUT, ">>" . $file) if(defined($file) && (! -d $file));
441 open(STDOUT, ">/dev/null") if(defined($file) && (-d $file));
442 print "BEGIN:VCALENDAR\r\nVERSION:1.0\r\n";
443 foreach my $row (@schedule) {
444 map { s/\n/-/g; $_} %$row;
445 $row->{'instructor'} =~ s/^([^,]*), ([^,]*)/$2 $1/;
446 $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
447 $row->{'days'} =~ s/^ //;
448 #$row->{'duration'} =~ s/(\d\d)-(\d\d)-(\d\d)/20$3$1$2/g;
449 my @day = (off_for_holidays(%$row),off_for_exams(%$row));
451 if(exists($day[0])) {
452 $day = join(";", @day);
453 $day =~ s/\b(\d{8})\b/$1T000000/g;
455 my ($starttime, $stoptime)=($row->{'begin'}, $row->{'end'});
456 my ($startdate, $stopdate)=split(/-/, $row->{'duration'});
459 if(defined($file) && (-d $file)) {
460 open FH, ">$file/" . $row->{'id'} . ".vcs" or die "$!";
462 print "BEGIN:VCALENDAR\r\nVERSION:1.0\r\n";
464 print "BEGIN:VEVENT\r\n";
465 print "SUMMARY:", $row->{'title'}, "\r\n";
466 print "DESCRIPTION:", $row->{'id'}, "\r\n";
467 print "LOCATION:", $row->{'location'}, "\r\n";
468 print "CATEGORIES:Education\r\n";
469 print "DTSTART:", $startdate."T".$starttime, "00\r\n";
470 print "DTEND:", $startdate."T".$stoptime, "00\r\n";
471 print "RRULE:W1 ", $row->{'days'} . " $stopdate", "T000000\r\n";
472 print("EXDATE:$day\r\n") if($day);
473 print "ATTENDEE;ROLE=OWNER;STATUS=CONFIRMED:", $opts{'name'}, "\r\n" if(defined($opts{'name'}));
474 print "ATTENDEE;ROLE=ORGANIZER;STATUS=CONFIRMED:", $row->{'instructor'}, " <" . (get_faculty_email($row->{'instructor'}) || "fake\@ddress"), ">\r\n";
475 print "END:VEVENT\r\n";
476 if(defined($file) && (-d $file)) {
477 print "END:VCALENDAR\r\n";
482 print "END:VCALENDAR\r\n";
485 sub do_html_schedule {
486 my @showheaders = ("Section ID/Title", "Instructor", "Days", "Time", "Duration", "Location");
488 my @schedule = get_schedule(@_);
489 print '<table id="schedule" cellpadding="3" cellspacing="0">'."\n<tr><th>";
490 print join("</th><th>",@showheaders);
491 print "</th></tr>\n";
492 foreach my $row (@schedule) {
493 map { s/\n/<br \/>/g; $_} %$row;
494 $row->{'time'} =~ s/-/-<wbr \/>/;
495 $row->{'duration'} =~ s/\d\d(\d\d)(\d\d)(\d\d)/$2-$3-$1/g;
496 print '<tr class="'.$shade.'">';
497 $shade = ($shade eq "dark"?"light":"dark");
498 print '<td class="idtitle">';
499 print '<span class="sectionid">' .$row->{'id'}. '</span><br />';
500 print '<span class="coursetitle">' .$row->{'title'}. '</span></td>';
501 my $instructor = $row->{'instructor'};
502 $instructor =~ s/^([^,]*), ([^,]*)(.*)/$2 $1$3/;
503 my $email = get_faculty_email($instructor);
505 #print '<td><a href="mailto:' . $email . '">'
506 #. $row->{'instructor'} . "</a></td>";
508 print "<td>" . $row->{'instructor'} . "</td>";
510 print "<td>" . $row->{'days'} . "</td>";
511 print "<td>" . $row->{'time'} . "</td>";
512 print "<td>" . $row->{'duration'} . "</td>";
513 print "<td>" . $row->{'location'} . "</td>";
520 my @readheaders = ("Section ID", "Course Title", "Grade", "Earned Hours", "Quality Hours", "Quality Points", "GPA");
521 @readheaders = ("Section", "Course Title", "FinalGrade", "Earned Hours", "Quality Hours", "Quality Points", "GPA") if($opts{'school'} eq 'tamuk');
522 my @showheaders = ("Section ID", "Course Title", "Grade", "Earned<br />Hours", "Quality<br />Hours", "Quality<br />Points");
525 my $te = new HTML::TableExtract( headers => [ @readheaders ] );
526 my $response = $ua->get("$url&tserve_tip_write=||WID|SID|PIN|Term&tserve_trans_config=rgrdterm.cfg"); # Valid grading terms
527 die $response->status_line unless $response->is_success;
528 #my @terms = reverse grep {s/^<option value="([^"]*)">.*/$1/} (split( /\r\n/, $response->content));
530 my $year = Date::Calc->localtime->year;
531 for(my $y=$year-4;$y<=$year;$y++) { push @terms, ($y.2,$y."F",$y.3,$y.4,$y.1,$y."S"); }
532 foreach(@_ ? @_ : @terms) {
533 $response = $ua->get("$url&tserve_tip_write=||WID|SID|PIN|Term&tserve_trans_config=rgrades.cfg&Term=".($_) );
534 die $response->status_line unless $response->is_success;
535 $te->parse($response->content);
537 print '<table id="grades" cellpadding="3" cellspacing="0">'."\n<tr>";
538 print '<th align="left" class="sectionid">', $showheaders[0];
539 print '</th><th align="left" class="coursetitle">', $showheaders[1];
540 print '</th><th align="center" class="grade">';
541 print join('</th><th align="center" class="right-number">',@showheaders[2 .. 5]);
542 print "</th></tr>\n";
543 foreach my $ts ($te->table_states) {
544 foreach my $row ($ts->rows) {
545 map { s/^\s+//; s/\xa0|\r//g; s/\n/<br \/>/g; $_} @$row;
546 $row->[1] = capitalize($row->[1]);
547 $row->[1] =~ s/&/&/g;
548 $row->[0] =~ s/Cumulative through/Cumulative: through/;
549 $row->[0] =~ s/Cumulative:(.*) (\d{4}) (.*)/Cumulative:$1 $3 $2/;
551 next if $row->[0] =~ /:|Current Term/;
552 print '<tr class="'.$shade.'">';
553 $shade = ($shade eq "dark"?"light":"dark");
554 print '<td align="left" class="sectionid">', $$row[0], '</td>';
555 print '<td align="left" class="coursetitle">', $$row[1], '</td>';
556 print '<td align="center" class="grade">';
557 #print join('</td><td>', @$row[0 .. 1]);
558 print join('</td><td align="right" class="right-number">', @$row[2 .. 5]);
559 print "</td></tr>\n";
562 print '<tr class="cumulative '.$shade.'"><td id="cumulative" colspan="2">', capitalize($lastrow->[0]);
563 #shift @$lastrow; shift @$lastrow;
564 print '</td><td align="center" id="gpa" class="grade">';
566 print '</td><td align="right" class="right-number">';
567 print join('</td><td align="right" class="right-number">', @$lastrow[3 .. 5]);
568 print "</td></tr>\n";
573 $response = $ua->get("$url&tserve_tip_write=||WID|SID|PIN&tserve_trans_config=rtranscr.cfg&CareerReqNum=1");
574 foreach (split /\n/, $response->content) {
575 next unless s/^\ |<pre>// || s/\ / /;
576 s/<\/?([Hh]\d|[Bb])>//g;
583 die "Grade support currently broken.\n";
584 do_html_grades(@ARGV);
585 } elsif ($arg eq "-s") {
586 do_html_schedule(@ARGV);
587 } elsif ($arg eq "-m") {
588 do_mhc_schedule(@ARGV);
589 } elsif ($arg eq "-c") {
590 do_csv_schedule(@ARGV);
591 } elsif ($arg eq "-v") {
592 do_vcalendar_schedule(@ARGV);
593 } elsif ($arg eq "-t") {
594 die "Transcript support currently broken.\n";
598 $ua->get("${url}twbkwbis.P_Logout"); # Logout