Nth_Weekday_of_Month_Year($year,9,7,1), +1) );
}
-if (-r $ENV{HOME} . "/.sctwebrc") {
- open CONFIG, $ENV{HOME} . "/.sctwebrc";
+my $config = $ENV{HOME} . "/.sctwebrc";
+if ($ARGV[0] eq '-F') {
+ shift;
+ $config = shift;
+}
+
+my $arg = "";
+$arg = shift if (defined($ARGV[0]) && $ARGV[0] =~ /^-\w$/);
+
+if (-r $config) {
+ open CONFIG, $config;
while(<CONFIG>) {
s/\#.*//;
next unless m/^([^=]*)=(.*)/;
$response = $ua->get("$url&tserve_tip_write=||WID|SID|PIN|Term&tserve_trans_config=" . ("regterm.cfg"||"rgrdterm.cfg")); # Valid terms
die $response->status_line unless $response->is_success;
-my @terms = grep {s/^<option value="([^"]*)">.*/$1/} (split( /\r\n/, $response->content));
+my @terms = grep {s/^<option value="([^"]*)">.*/$1/} (split( /\r\n/, $response->content)); # "
+if(@terms) {
+ $opts{school} = 'accd';
+} else {
+ $response = $ua->get("$url&tserve_tip_write=||WID|SID|PIN|Term&tserve_trans_config=aterm.cfg"); # Valid terms
+ die $response->status_line unless $response->is_success;
+ @terms = grep {s/&Term=(\w*)$/$1/} (split( /\r\n/, $response->content));
+ $opts{school} = 'tamuk';
+}
die "Site down. Try again later.\n" unless (@terms);
sub generate_id {
} elsif($time =~ /$ending/) {
return $lastday-5;
}
+ } elsif($days eq "5") {
+ return $lastday-2;
}
return wantarray ? () : "";
}
sub capitalize {
- local $_ = shift;
+ local $_ = shift || "";
s/ +$//;
s/\b([A-Z])([A-Z]*)\b/$1\L$2/g;
s/\b(I)(i*)\b/$1\U$2/g;
#s/\bGovt\b/Government/g;
s/\bLit\b/Literature/g;
s/\bPrin\b/Principles/g;
+ s/\bBus\b/Business/g;
return $_;
}
sub get_schedule_terms {
- my @terms;
+ my (@sterms, @a);
+ if($opts{school} eq 'tamuk') {
+ @a=('F','S','1','2');
+ } else {
+ @a=('1','2','3','4');
+ }
my @localtime=localtime();
if ($localtime[4]<3) { # Through Mar 31
- @terms=((1900+$localtime[5])*10+2);
+ @sterms=((1900+$localtime[5]).$a[1]);
} elsif ($localtime[4]<5) { # Through May 31
- @terms=((1900+$localtime[5])*10+2,(1900+$localtime[5])*10+3);
+ @sterms=((1900+$localtime[5]).$a[1],(1900+$localtime[5]).$a[2]);
} elsif ($localtime[4]<7) { # through July 31
- @terms=((1900+$localtime[5])*10+3,(1900+$localtime[5])*10+4);
+ @sterms=((1900+$localtime[5]).$a[2],(1900+$localtime[5]).$a[3]);
} elsif ($localtime[4]<8) { # through Aug 31
- @terms=((1900+$localtime[5])*10+4,(1900+$localtime[5])*10+1);
+ @sterms=((1900+$localtime[5]).$a[3],(1900+$localtime[5]).$a[0]);
} elsif ($localtime[4]<10) { # through Oct 31
- @terms=((1900+$localtime[5])*10+1);
+ @sterms=((1900+$localtime[5]).$a[0]);
} else {
- @terms=((1900+$localtime[5])*10+1,(1901+$localtime[5])*10+2);
+ @sterms=((1900+$localtime[5]).$a[0],(1901+$localtime[5]).$a[1]);
}
- return @terms;
+ return @sterms;
}
sub get_schedule {
my @readheaders = ("Section ID/Title", "Session", "Instructor", "Credits", "CallNumber","GradeType", "Days", "Time", "Start/EndDates", "Site/Building/Room", "Message");
my $te = new HTML::TableExtract( headers => [ @readheaders ] );
- my (@schedule, @terms, $classid, $begin, $end);
+ @readheaders = ("Course", "Days\xa0TimeLocation", "Session and Dates", "Instructor", "Credit", "CallNumber", "GradeType", "Message");
+ my $tf = new HTML::TableExtract( headers => [ @readheaders ] );
+ my (@schedule, @terms, $classid, $begin, $end, $times, $days, $session);
@terms = get_schedule_terms();
- foreach(@_ || @terms) {
+ foreach (@_ ? @_ : @terms) {
$response = $ua->get("$url&tserve_tip_write=||WID|SID|PIN|Term&tserve_trans_config=rstusch.cfg&Term=".($_) );
die $response->status_line unless $response->is_success;
$te->parse($response->content);
+ $tf->parse($response->content);
+ #print $response->content;
}
foreach my $ts ($te->table_states) {
foreach my $row ($ts->rows) {
};
}
}
+ foreach my $ts ($tf->table_states) {
+ foreach my $row ($ts->rows) {
+ next if ($row->[0] =~ /Total Enrolled Hours/);
+ $row->[1] =~ s/\xa0/ /g;
+ map { s/\xa0//g; $_} @$row;
+ map { s/^\r?\n? *//g; $_} @$row;
+ $row->[0] =~ s/.*launchWebCT\("([^"]*)"[^)]*\).*>\s*//s;
+ $classid=$1;
+ $row->[0] =~ s/(.*)/capitalize($1)/eg;
+ $row->[1] =~ s/^([MTWRFS]*) *([0-9:-]*[AP]M)\s*//;
+ ($days, $times) = ($1, $2);
+ ($begin, $end) = split("-", $times);
+ if($times =~ /^(\d\d):\d\d-(\d\d):\d\dPM$/) {
+ if($1 < $2 && $2 != 12) {
+ $begin =~ s/^(\d\d)/$1+12/e;
+ }
+ if($2 != 12) {
+ $end =~ s/^(\d\d)/$1+12/e;
+ }
+ $end =~ s/PM$//;
+ } else { $end =~ s/AM$//; }
+ $row->[2] =~ s/(.*\S)\s*//;
+ $session = $1;
+ $row->[2] =~ s/(\d\d)-(\d\d)-(\d\d)/20$3$1$2/g;
+ $row->[2] =~ s/ *to */\n/g;
+ $row->[3] = capitalize($row->[3]);
+ $row->[3] =~ s/([A-Z]r?)$/$1./;
+ push @schedule, {
+ id => $classid,
+ title => $row->[0],
+ session => $session,
+ instructor => $row->[3],
+ credits => $row->[4],
+ callnumber => $row->[5],
+ gradetype => $row->[6],
+ days => $days,
+ 'time' => $times,
+ begin => $begin,
+ end => $end || undef,
+ duration => $row->[2],
+ location => $row->[1],
+ message => $row->[7],
+ };
+ }
+ }
return @schedule;
}
open INS, $ENV{'HOME'} . "/public_html/faculty.csv";
while($_ = <INS>) {
chomp;
- m/"([^"]*)",([^,]*),([^,]*)/;
+ m/"([^"]*)",([^,]*),([^,]*)/; # "
($name, $email, $school) = ($1, $2, $3);
$name =~ s/^([^,]*), ([^,]*)(.*)$/$2 $1$3/;
$name =~ s/ [A-Z]\.//g;
sub do_html_schedule {
my @showheaders = ("Section ID/Title", "Instructor", "Days", "Time", "Duration", "Location");
+ my $shade = "dark";
my @schedule = get_schedule(@_);
- print '<table cellpadding="3" cellspacing="0">'."\n<tr><th>";
+ print '<table id="schedule" cellpadding="3" cellspacing="0">'."\n<tr><th>";
print join("</th><th>",@showheaders);
print "</th></tr>\n";
foreach my $row (@schedule) {
map { s/\n/<br \/>/g; $_} %$row;
$row->{'time'} =~ s/-/-<wbr \/>/;
$row->{'duration'} =~ s/\d\d(\d\d)(\d\d)(\d\d)/$2-$3-$1/g;
- print '<tr>';
- print "<td>" . $row->{'id'} . "<br />" . $row->{'title'} . "</td>";
+ print '<tr class="'.$shade.'">';
+ $shade = ($shade eq "dark"?"light":"dark");
+ print '<td class="idtitle">';
+ print '<span class="sectionid">' .$row->{'id'}. '</span><br />';
+ print '<span class="coursetitle">' .$row->{'title'}. '</span></td>';
my $instructor = $row->{'instructor'};
$instructor =~ s/^([^,]*), ([^,]*)(.*)/$2 $1$3/;
my $email = get_faculty_email($instructor);
sub do_html_grades {
my @readheaders = ("Section ID", "Course Title", "Grade", "Earned Hours", "Quality Hours", "Quality Points", "GPA");
- my @showheaders = ("Section ID", "Course Title", "Grade", "Earned<br />Hours", "Quality<br />Hours", "Quality<br />Points", "GPA");
+ @readheaders = ("Section", "Course Title", "FinalGrade", "Earned Hours", "Quality Hours", "Quality Points", "GPA") if($opts{'school'} eq 'tamuk');
+ my @showheaders = ("Section ID", "Course Title", "Grade", "Earned<br />Hours", "Quality<br />Hours", "Quality<br />Points");
my ($row, $lastrow);
+ my $shade = "dark";
my $te = new HTML::TableExtract( headers => [ @readheaders ] );
my $response = $ua->get("$url&tserve_tip_write=||WID|SID|PIN|Term&tserve_trans_config=rgrdterm.cfg"); # 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 @terms = ();
my $year = Date::Calc->localtime->year;
- for(my $y=$year-4;$y<=$year;$y++) { push @terms, ($y.2,$y.3,$y.4,$y.1); }
+ for(my $y=$year-4;$y<=$year;$y++) { push @terms, ($y.2,$y."F",$y.3,$y.4,$y.1,$y."S"); }
foreach(@_ ? @_ : @terms) {
$response = $ua->get("$url&tserve_tip_write=||WID|SID|PIN|Term&tserve_trans_config=rgrades.cfg&Term=".($_) );
die $response->status_line unless $response->is_success;
$te->parse($response->content);
}
- print '<table cellpadding="3" cellspacing="0">'."\n<tr><th>";
- print join("</th><th>",@showheaders);
+ print '<table id="grades" cellpadding="3" cellspacing="0">'."\n<tr>";
+ print '<th align="left" class="sectionid">', $showheaders[0];
+ print '</th><th align="left" class="coursetitle">', $showheaders[1];
+ print '</th><th align="center" class="grade">';
+ print join('</th><th align="center" class="right-number">',@showheaders[2 .. 5]);
print "</th></tr>\n";
foreach my $ts ($te->table_states) {
foreach my $row ($ts->rows) {
- map { s/\xa0//g; s/\n/<br \/>/g; $_} @$row;
+ map { s/^\s+//; s/\xa0|\r//g; s/\n/<br \/>/g; $_} @$row;
$row->[1] = capitalize($row->[1]);
+ $row->[1] =~ 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] =~ /:/;
- print '<tr><td>';
- print join('</td><td>', @$row);
+ next if $row->[0] =~ /:|Current Term/;
+ print '<tr class="'.$shade.'">';
+ $shade = ($shade eq "dark"?"light":"dark");
+ print '<td align="left" class="sectionid">', $$row[0], '</td>';
+ print '<td align="left" class="coursetitle">', $$row[1], '</td>';
+ print '<td align="center" class="grade">';
+ #print join('</td><td>', @$row[0 .. 1]);
+ print join('</td><td align="right" class="right-number">', @$row[2 .. 5]);
print "</td></tr>\n";
}
}
- print '<tr><td colspan="2">', capitalize($lastrow->[0]);
- shift @$lastrow; shift @$lastrow;
- print "</td><td>";
- print join('</td><td>', @$lastrow);
+ print '<tr class="cumulative '.$shade.'"><td id="cumulative" colspan="2">', capitalize($lastrow->[0]);
+ #shift @$lastrow; shift @$lastrow;
+ print '</td><td align="center" id="gpa" class="grade">';
+ print $$lastrow[6];
+ print '</td><td align="right" class="right-number">';
+ print join('</td><td align="right" class="right-number">', @$lastrow[3 .. 5]);
print "</td></tr>\n";
print "</table>\n";
}
$response = $ua->get("$url&tserve_tip_write=||WID|SID|PIN&tserve_trans_config=rtranscr.cfg&CareerReqNum=1");
foreach (split /\n/, $response->content) {
next unless s/^\ |<pre>// || s/\ / /;
- s/<\/?[Hh]\d>//g;
+ s/<\/?([Hh]\d|[Bb])>//g;
+ next if /<\/td>/;
print "$_\n";
}
}
-my $arg = "";
-$arg = shift if (defined($ARGV[0]) && $ARGV[0] =~ /^-\w$/);
-
-if ($arg eq "-g") {
- do_html_grades(@ARGV);
-} elsif ($arg eq "-s") {
+if ($arg eq "-s") {
do_html_schedule(@ARGV);
} elsif ($arg eq "-m") {
do_mhc_schedule(@ARGV);
do_csv_schedule(@ARGV);
} elsif ($arg eq "-v") {
do_vcalendar_schedule(@ARGV);
+} elsif ($arg eq "-g") {
+ do_html_grades(@ARGV);
} elsif ($arg eq "-t") {
do_transcripts;
} elsif ($arg eq "-f") {