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.
10 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);
11 use Date::Calendar::Profiles qw($Profiles);
12 use Date::Calendar::Year;
13 use HTML::TableExtract;
16 use vars qw($ua %opts %faculty);
20 $opts{'holidays'} = { # %{$Profiles->{'US-TX'}},
21 "Martin Luther King Day" => "3/Mon/Jan",
22 "Good Friday" => "-2",
23 "Spring Break Monday" => \&Spring_Break,
24 "Spring Break Tuesday" => \&Spring_Break,
25 "Spring Break Wednesday" => \&Spring_Break,
26 "Spring Break Thursday" => \&Spring_Break,
27 "Spring Break Friday" => \&Spring_Break,
28 "Spring Break Saturday" => \&Spring_Break,
29 "Study Day" => "4/Thu/Apr", # ?
30 "Memorial Day" => "5/Mon/May",
31 "Independence Day" => \&US_Independence,
32 "Labor Day" => \&US_Labor,
33 #"Columbus Day" => "2/Mon/Oct",
34 "Thanksgiving Day" => "4/Thu/Nov",
35 "Thanksgiving Friday" => \&Thanksgiving_Friday,
39 my($year,$label) = @_;
40 $label =~ s/^Spring Break //;
41 return( Add_Delta_Days(
42 Nth_Weekday_of_Month_Year($year,1,1,1),
43 7*(11-1) # This is for the 11th Monday of the year
44 +Decode_Day_of_Week($label)-1) );
47 sub Thanksgiving_Friday {
48 my($year,$label) = @_;
49 return( Add_Delta_Days(Nth_Weekday_of_Month_Year($year,11,4,4), 1) );
51 sub US_Independence # Fourth of July
53 my($year,$label) = @_;
54 return( &Date::Calendar::Profiles::Nearest_Workday($year,7,4) );
56 sub US_Labor # First Monday after the first Sunday in September
58 my($year,$label) = @_;
59 return( Add_Delta_Days(
60 Nth_Weekday_of_Month_Year($year,9,7,1), +1) );
63 my $config = $ENV{HOME} . "/.sct6rc";
64 if (($ARGV[0] || "") eq '-F') {
70 $arg = shift if (defined($ARGV[0]) && $ARGV[0] =~ /^-\w$/);
76 next unless m/^([^=]*)=(.*)/;
81 my $domain = $opts{'domain'} || "as1.tamuk.edu:9003";
82 my $url = "https://$domain/pls/PROD/";
83 $url = $opts{'url'} if(defined($opts{'url'}));
85 $ua = LWP::UserAgent->new;
88 $ua->cookie_jar( {} );
89 $ua->get("${url}twbkwbis.P_WWWLogin") or die "$!";
90 $response = $ua->post("${url}twbkwbis.P_ValLogin", { sid => $opts{SID}, PIN => $opts{PIN} }) or die "$!";
92 $response = $ua->get("${url}bwskflib.P_SelDefTerm"); # Valid terms
93 die $response->status_line unless $response->is_success;
94 my @terms = grep {s/^<option value="([^"]*)">.*/$1/i} (split( /\r?\n/, $response->content)); # "
95 die "Site down. Try again later.\n" unless (@terms);
98 my ($section, $number) = split("-", shift);
100 foreach (split //, $section) {$id=26*$id+(ord($_)-1)%32;}
101 $id=10000*$id+$number;
107 $class{'duration'} =~ /(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)/;
108 my $days = Delta_Days($1,$2,$3,$4,$5,$6);
109 my $firstday = Date::Calc->new($1,$2,$3);
110 my $lastday = Date::Calc->new($4,$5,$6);
111 my $today = Date::Calc->new(Date::Calc->localtime(time+3600*6)->date);
113 foreach(split(" ",$class{'days'})) {
114 push @days, Decode_Day_of_Week($_);
116 my @off = @{$row->{'off'}};
117 for($today = ($today > $firstday ? $today : $firstday); $today < $lastday; $today++) {
118 next unless(grep($_ == Day_of_Week($today->date), @days));
119 next if(grep($_ == $today, @off));
122 $today = Date::Calc->new(Date::Calc->gmtime->date);
123 for($today = ($today < $lastday ? $today : $lastday); $today > $firstday; $today--) {
124 next unless(grep($_ == Day_of_Week($today->date), @days));
125 next if(grep($_ == $today, @off));
131 sub off_for_holidays {
133 my %days = (M => "Mon", T => "Tue", W => "Wed", R => "Thu", F => "Fri", S => "Sat", U => "SU");
134 my $d = $class{'days'};
135 $d =~ s/([MTWRFS])/ $days{$1}/g;
137 $class{'duration'} =~ /(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)/;
138 my $days = Delta_Days($1,$2,$3,$4,$5,$6);
139 my $firstday = Date::Calc->new($1,$2,$3);
140 my $lastday = Date::Calc->new($4,$5,$6);
141 my $year = Date::Calendar::Year->new($1, $opts{'holidays'});
144 foreach(split(" ",$d)) {
145 $days[Decode_Day_of_Week($_)] = 1;
147 foreach ($year->search("")) {
149 #foreach my $x ($year->labels($_)) {
150 # $good=0 if ($x =~ /Veteran/ or $x =~ /President/);
152 next unless ($year->is_full($_) && $_>=$firstday && $_<=$lastday);
154 if (defined($days[Day_of_Week($_->date)]) && $good > 0);
156 return wantarray ? @holidays : "@holidays";
161 my $time = $class{'begin'} . "-" . $class{'end'};
162 $class{'duration'} =~ /\d{8}-(\d\d\d\d)(\d\d)(\d\d)/;
163 my $lastday = Date::Calc->new($1,$2,$3);
164 return wantarray ? () : undef unless (Day_of_Week($lastday->date) == 7);
165 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)";
166 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)";
167 my $days = join(" ",map {Decode_Day_of_Week($_)} split(/ /, $class{'days'}));
169 if($time =~ /$beginning/) {
171 } elsif($time =~ /$ending/) {
174 } elsif($days eq "2 4") {
175 if($time =~ /$beginning/) {
177 } elsif($time =~ /$ending/) {
180 } elsif($days eq "5") {
183 return wantarray ? () : "";
187 local $_ = shift || "";
189 s/\b([A-Z])([A-Z]*)\b/$1\L$2/g;
190 s/\b(I)(i*)\b/$1\U$2/g;
192 s/ (And|For|Of|Or|The|To|With) / \l$1 /g;
193 s/\b(Mc)([a-z])/$1\u$2/g;
194 s/\b(Tcp\/Ip|Pc|Tba)\b/\U$&/g;
195 s/\bThru\b/Through/g;
196 s/\bAcct\b/Accounting/g;
197 s/\bAmer\b/American/g;
198 s/\bChem\b/Chemistry/g;
199 s/\bComp\b/Composition/g;
202 s/\bIntro\b/Introduction/g;
203 s/\bPrgm\b/Programming/g;
204 s/\bOp Sys\b/Operating System/g;
205 #s/\bGovt\b/Government/g;
206 s/\bLit\b/Literature/g;
207 s/\bPrin\b/Principles/g;
208 s/\bBus\b/Business/g;
213 sub get_schedule_terms {
215 @a=('10','20','30','40'); # Fall, Spring, Summer I, Summer II
216 # Last 3 are currently guesses
217 my @localtime=localtime();
218 if ($localtime[4]<3) { # Through Mar 31
219 @sterms=((1900+$localtime[5]).$a[1]);
220 } elsif ($localtime[4]<5) { # Through May 31
221 @sterms=((1900+$localtime[5]).$a[1],(1900+$localtime[5]).$a[2]);
222 } elsif ($localtime[4]<7) { # through July 31
223 @sterms=((1900+$localtime[5]).$a[2],(1900+$localtime[5]).$a[3]);
224 } elsif ($localtime[4]<8) { # through Aug 31
225 @sterms=((1900+$localtime[5]).$a[3],(1901+$localtime[5]).$a[0]);
226 } elsif ($localtime[4]<10) { # through Oct 31
227 @sterms=((1901+$localtime[5]).$a[0]);
229 @sterms=((1901+$localtime[5]).$a[0],(1901+$localtime[5]).$a[1]);
235 my @readheaders = ("Type", "Time", "Days", "Where", "Date Range", "Schedule Type", "Instructors");
237 my $te = new HTML::TableExtract( headers => [ @readheaders ] );
238 my (@schedule, @terms, $classid, $title, $begin, $end, $times, $days, $session);
239 @terms = get_schedule_terms();
240 foreach (@_ ? @_ : @terms) {
241 $response = $ua->get("${url}bwskfshd.P_CrseSchdDetl?term_in=$_" );
242 die $response->status_line unless $response->is_success;
243 $te->parse($response->content);
244 foreach my $l (split (/\n/, $response->content)) {
245 next unless $l =~ s/.*<CAPTION class=[^>]*>(.* - .... \d\d\d\d \d\d\d)<\/caption>.*/$1/i;
249 foreach my $ts ($te->table_states) {
250 foreach my $row ($ts->rows) {
251 #map { s/\xa0//g; $_} @$row;
252 #$row->[0] =~ s/.*launchWebCT\("([^"]*)"\).*/$1/s;
253 #$row->[0] =~ s/(.*) ?<[Bb][Rr][^>]*>(.*)/capitalize($2)/eg;
254 $classid = (shift @class);
256 $classid =~ s/.* - //;
259 $row->[6] =~ s/\b([A-Z]r?)$/$1./;
260 $row->[6] = capitalize($row->[6]);
261 $row->[6] =~ s/ *\([A-Z]\)//;
262 $row->[1] =~ s/ ?([ap])m/\u$1M/g;
263 $row->[1] =~ s/ - /-/;
264 ($begin, $end) = split(/ ?- ?/, $row->[1]);
265 $begin =~ s/^(\d):/0$1:/;
266 $end =~ s/^(\d):/0$1:/;
267 if (($begin=~/PM$/ && $begin!~/^12/)||($begin=~/^12:..AM/)) {
268 $begin =~ s/^(\d?\d)/($1+12)%24/e;
270 if (($end=~/PM$/ && $end!~/^12/)||($end=~/^12:..AM/)) {
271 $end =~ s/^(\d?\d)/($1+12)%24/e;
273 $begin =~ s/ ?[AP]M//;
275 $row->[4] =~ s/([A-Za-z]{3,9})/(Decode_Month($1)<10?"0":"").Decode_Month($1)/eg;
276 $row->[4] =~ s/(\d\d?) (\d\d), (\d\d\d\d)/$3$1$2/g;
277 $row->[4] =~ s/ - /-/;
278 $row->[3] =~ s/(ON|MAIN) CAMPUS\n|Palo Alto Building \d* //ig;
279 $row->[3] =~ s/\n/ /g;
282 title => capitalize($title),
283 instructor => $row->[6],
285 #'time' => $row->[1],
287 end => $end || undef,
288 duration => $row->[4],
289 location => $row->[3],
291 my @off = ( map { "$_"; } (off_for_holidays(%class), off_for_exams(%class)));
292 $class{'off'} = [ @off ] if (@off);
293 push @schedule, \%class;
299 sub get_faculty_email {
300 my ($name, $school, $email);
301 if((-f $ENV{'HOME'} . "/public_html/faculty.csv") && ! %faculty) {
302 open INS, $ENV{'HOME'} . "/public_html/faculty.csv";
305 m/"([^"]*)",([^,]*),([^,]*)/; # "
306 ($name, $email, $school) = ($1, $2, $3);
307 #$name =~ s/^([^,]*), ([^,]*)(.*)$/$2 $1$3/;
308 $name =~ s/ [A-Z]\.//g;
311 $faculty{$name} = $email;
315 $name =~ s/ [A-Z]r?\.//g;
318 return $faculty{$name};
323 "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",
324 "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",
325 "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",
326 "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",
327 "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",
328 "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",
329 "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",
330 "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",
331 "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",
332 "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",
336 sub do_mhc_schedule {
338 my %days = (M => "Mon", T => "Tue", W => "Wed", R => "Thu", F => "Fri", S => "Sat", U => "SU");
339 my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
340 my ($file, $current, @mhc, @schedule);
341 $file = shift unless (!defined $_[0] or $_[0] =~ /^\d/);
342 @schedule = get_schedule(@_);
343 @mhc = get_mhc_header;
344 if(defined($file) && (-d $file)) {
347 $_ =~ s/X-SC-Subject: ([^\n]*)/X-SC-Subject: $1\nSubject: $1/;
348 $_ =~ s/X-SC-Category: ([^\n]*)/X-SC-Category: $1\nFrom: $1/;
349 $_ =~ 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;
354 foreach my $row (@schedule) {
355 #my @day = map { "!" . $_ } (off_for_holidays(%$row),off_for_exams(%$row));
356 my @day = @{$row->{'off'}};
357 map {s/\n/-/g if defined; $_} %$row;
358 my $id=generate_id($row->{'id'});
359 $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
360 $row->{'days'} =~ s/^ //;
361 #$row->{'duration'} =~ s/(\d\d)-(\d\d)-(\d\d)/20$3$1$2/g;
364 $current .= "X-SC-Subject: " . $row->{'title'} . "\n";
365 $current .= "X-SC-Location: " . $row->{'location'} . "\n";
366 $current .= "X-SC-Category: School\n";
367 $current .= "X-SC-Cond: " . $row->{'days'} . "\n";
368 $current .= "X-SC-Time: ".$row->{'begin'}."-".$row->{'end'}."\n";
369 $current .= "X-SC-Duration: " . $row->{'duration'} . "\n";
370 $current .= "X-SC-Day: @day\n" if(exists $day[0]);
371 $current .= "X-SC-Alarm: 15 minutes\n";
372 $current .= "X-SC-Record-Id: <".$row->{'id'}."\@from.sctweb>\n";
373 if(defined($file) && (-d $file)) {
374 #$row->{'instructor'} =~ s/^([^,]*), ([^,]*)(.*)/$2 $1$3/;
375 my $email = get_faculty_email $row->{'instructor'};
376 $row->{'instructor'} = '"' . $row->{'instructor'} . '" <'. ($email || ($1 || "unknown") . "\@from.sctweb") . ">";
377 $row->{'duration'} =~ /^(\d\d\d\d)(\d\d)(\d\d)-\d{8}$/;
378 $row->{'begin'} =~ /^(\d\d):(\d\d)$/;
379 my $next = next_class(%$row);
380 my @date = Gmtime(Mktime($next->date,$1,$2,0));
381 $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];
382 $current .= "Subject: " . $row->{'title'} . "\n";
383 $current .= "From: " . $row->{'instructor'} . "\n";
388 if(defined($file) && (-d $file)) {
390 foreach my $name (<$file/[1-9]*>) {
391 next unless $name =~ /^$file\/[1-9][0-9]*$/;
396 unlink $name if /^X-SC-Record-Id: <.*\@from.sctweb>/;
402 open FH, ">$file/$i" or die $!;
407 open(STDOUT, ">" . $file) if(defined($file));
408 print "# MHC school schedule\n# Autogenerated by sctweb ".localtime()."\n\n";
409 print join("\n", @mhc);
413 sub do_csv_schedule {
415 my %days = (M => "Mon", T => "Tue", W => "Wed", R => "Thu", F => "Fri", S => "Sat", U => "SU");
416 my @mon = qw(Jan. Feb. Mar. Apr. May June July Aug. Sept. Oct. Nov. Dec.);
417 my (@terms, $file, $current, @mhc, @schedule);
418 $file = shift unless (!defined $_[0] or $_[0] =~ /^\d/);
419 @schedule = get_schedule(@_);
420 open(STDOUT, ">" . $file) if(defined($file));
421 foreach my $row (@schedule) {
422 map {s/\n/-/g if defined; $_} %$row;
423 my $id=generate_id($row->{'id'});
424 $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
425 $row->{'days'} =~ s/^ //;
426 #$row->{'instructor'} =~ s/^([^,]*), ([^,]*)(.*)$/$2 $1$3/;
427 my $next = next_class(%$row);
430 $current .= $row->{'id'} . ",";
431 $current .= $row->{'title'} . ",";
432 $current .= '"' . $row->{'instructor'} . '",';
433 $next =~ /^(\d\d\d\d)(\d\d)(\d\d)$/;
434 $current .= $1 . "-". $2 ."-" . $3 . "\n";
439 sub do_vcalendar_schedule {
441 my %days = (M => "MO", T => "TU", W => "WE", R => "TH", F => "FR", S => "SA", U => "SU");
442 my $file = shift if (defined $_[0] and $_[0] !~ /^\d/);
443 my @schedule = get_schedule(@_);
444 open(STDOUT, ">>" . $file) if(defined($file) && (! -d $file));
445 open(STDOUT, ">/dev/null") if(defined($file) && (-d $file));
446 print "BEGIN:VCALENDAR\r\nVERSION:1.0\r\n";
447 foreach my $row (@schedule) {
448 map { s/\n/-/g; $_} %$row;
449 #$row->{'instructor'} =~ s/^([^,]*), ([^,]*)/$2 $1/;
450 $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
451 $row->{'days'} =~ s/^ //;
452 #$row->{'duration'} =~ s/(\d\d)-(\d\d)-(\d\d)/20$3$1$2/g;
453 my @day = @{$row->{'off'}};
455 if(exists($day[0])) {
456 $day = join(";", @day);
457 $day =~ s/\b(\d{8})\b/$1T000000/g;
459 my ($starttime, $stoptime)=($row->{'begin'}, $row->{'end'});
460 my ($startdate, $stopdate)=split(/-/, $row->{'duration'});
463 if(defined($file) && (-d $file)) {
464 open FH, ">$file/" . $row->{'id'} . ".vcs" or die "$!";
466 print "BEGIN:VCALENDAR\r\nVERSION:1.0\r\n";
468 print "BEGIN:VEVENT\r\n";
469 print "SUMMARY:", $row->{'title'}, "\r\n";
470 print "DESCRIPTION:", $row->{'id'}, "\r\n";
471 print "LOCATION:", $row->{'location'}, "\r\n";
472 print "CATEGORIES:Education\r\n";
473 print "DTSTART:", $startdate."T".$starttime, "00\r\n";
474 print "DTEND:", $startdate."T".$stoptime, "00\r\n";
475 print "RRULE:W1 ", $row->{'days'} . " $stopdate", "T000000\r\n";
476 print("EXDATE:$day\r\n") if($day);
477 print "ATTENDEE;ROLE=OWNER;STATUS=CONFIRMED:", $opts{'name'}, "\r\n" if(defined($opts{'name'}));
478 print "ATTENDEE;ROLE=ORGANIZER;STATUS=CONFIRMED:", $row->{'instructor'}, " <" . (get_faculty_email($row->{'instructor'}) || "fake\@ddress"), ">\r\n";
479 print "END:VEVENT\r\n";
480 if(defined($file) && (-d $file)) {
481 print "END:VCALENDAR\r\n";
486 print "END:VCALENDAR\r\n";
489 sub do_xml_schedule {
490 my $file = shift if (defined $_[0] and $_[0] !~ /^\d/);
491 my $schedule = { class => [ get_schedule(@_) ] };
492 my $xml = XMLout($schedule, NoAttr => 1, RootName => 'schedule');
502 sub do_html_schedule {
503 my @showheaders = ("Section ID/Title", "Instructor", "Days", "Time", "Duration", "Location");
505 my @schedule = get_schedule(@_);
506 print '<table id="schedule" cellpadding="3" cellspacing="0">'."\n<tr><th>";
507 print join("</th><th>",@showheaders);
508 print "</th></tr>\n";
509 foreach my $row (@schedule) {
510 map { s/\n/<br \/>/g; $_} %$row;
511 $row->{'duration'} =~ s/-/<br \/>/g;
512 $row->{'duration'} =~ s/\d\d(\d\d)(\d\d)(\d\d)/$2-$3-$1/g;
513 print '<tr class="'.$shade.'">';
514 $shade = ($shade eq "dark"?"light":"dark");
515 print '<td class="idtitle">';
516 print '<span class="sectionid">' .$row->{'id'}. '</span><br />';
517 print '<span class="coursetitle">' .$row->{'title'}. '</span></td>';
518 my $instructor = $row->{'instructor'};
519 #$instructor =~ s/^([^,]*), ([^,]*)(.*)/$2 $1$3/;
520 my $email = get_faculty_email($instructor);
522 #print '<td><a href="mailto:' . $email . '">'
523 #. $row->{'instructor'} . "</a></td>";
525 print "<td>" . $row->{'instructor'} . "</td>";
527 print "<td>" . $row->{'days'} . "</td>";
528 print "<td>" . $row->{'begin'}."-<wbr />".$row->{'end'} . "</td>";
529 print "<td>" . $row->{'duration'} . "</td>";
530 print "<td>" . $row->{'location'} . "</td>";
537 my @readheaders = ("Section ID", "Course Title", "Grade", "Earned Hours", "Quality Hours", "Quality Points", "GPA");
538 @readheaders = ("Section", "Course Title", "FinalGrade", "Earned Hours", "Quality Hours", "Quality Points", "GPA") if($opts{'school'} eq 'tamuk');
539 my @showheaders = ("Section ID", "Course Title", "Grade", "Earned<br />Hours", "Quality<br />Hours", "Quality<br />Points");
542 my $te = new HTML::TableExtract( headers => [ @readheaders ] );
543 my $response = $ua->get("$url&tserve_tip_write=||WID|SID|PIN|Term&tserve_trans_config=rgrdterm.cfg"); # Valid grading terms
544 die $response->status_line unless $response->is_success;
545 #my @terms = reverse grep {s/^<option value="([^"]*)">.*/$1/} (split( /\r\n/, $response->content));
547 my $year = Date::Calc->localtime->year;
548 for(my $y=$year-4;$y<=$year;$y++) { push @terms, ($y.2,$y."F",$y.3,$y.4,$y.1,$y."S"); }
549 foreach(@_ ? @_ : @terms) {
550 $response = $ua->get("$url&tserve_tip_write=||WID|SID|PIN|Term&tserve_trans_config=rgrades.cfg&Term=".($_) );
551 die $response->status_line unless $response->is_success;
552 $te->parse($response->content);
554 print '<table id="grades" cellpadding="3" cellspacing="0">'."\n<tr>";
555 print '<th align="left" class="sectionid">', $showheaders[0];
556 print '</th><th align="left" class="coursetitle">', $showheaders[1];
557 print '</th><th align="center" class="grade">';
558 print join('</th><th align="center" class="right-number">',@showheaders[2 .. 5]);
559 print "</th></tr>\n";
560 foreach my $ts ($te->table_states) {
561 foreach my $row ($ts->rows) {
562 map { s/^\s+//; s/\xa0|\r//g; s/\n/<br \/>/g; $_} @$row;
563 $row->[1] = capitalize($row->[1]);
564 $row->[1] =~ s/&/&/g;
565 $row->[0] =~ s/Cumulative through/Cumulative: through/;
566 $row->[0] =~ s/Cumulative:(.*) (\d{4}) (.*)/Cumulative:$1 $3 $2/;
568 next if $row->[0] =~ /:|Current Term/;
569 print '<tr class="'.$shade.'">';
570 $shade = ($shade eq "dark"?"light":"dark");
571 print '<td align="left" class="sectionid">', $$row[0], '</td>';
572 print '<td align="left" class="coursetitle">', $$row[1], '</td>';
573 print '<td align="center" class="grade">';
574 #print join('</td><td>', @$row[0 .. 1]);
575 print join('</td><td align="right" class="right-number">', @$row[2 .. 5]);
576 print "</td></tr>\n";
579 print '<tr class="cumulative '.$shade.'"><td id="cumulative" colspan="2">', capitalize($lastrow->[0]);
580 #shift @$lastrow; shift @$lastrow;
581 print '</td><td align="center" id="gpa" class="grade">';
583 print '</td><td align="right" class="right-number">';
584 print join('</td><td align="right" class="right-number">', @$lastrow[3 .. 5]);
585 print "</td></tr>\n";
590 $response = $ua->get("$url&tserve_tip_write=||WID|SID|PIN&tserve_trans_config=rtranscr.cfg&CareerReqNum=1");
591 foreach (split /\n/, $response->content) {
592 next unless s/^\ |<pre>// || s/\ / /;
593 s/<\/?([Hh]\d|[Bb])>//g;
599 if ($arg eq "-s" || $arg eq "-h") {
600 do_html_schedule(@ARGV);
601 } elsif ($arg eq "-m") {
602 do_mhc_schedule(@ARGV);
603 } elsif ($arg eq "-c") {
604 do_csv_schedule(@ARGV);
605 } elsif ($arg eq "-v") {
606 do_vcalendar_schedule(@ARGV);
607 } elsif ($arg eq "-g") {
608 die "Grade support currently broken.\n";
609 do_html_grades(@ARGV);
610 } elsif ($arg eq "-t") {
611 die "Transcript support currently broken.\n";
613 } elsif ($arg eq "-x" || 1) {
614 do_xml_schedule(@ARGV);
617 $ua->get("${url}twbkwbis.P_Logout"); # Logout