#!/usr/bin/perl #require "formlib.pl"; use CGI qw/:standard/; require LWP::Protocol::http; require LWP::Protocol::https; require LWP::UserAgent; require URI::URL; # # swebget is at http://www.uni-hildesheim.de/~smol0075/webget/ $start_time = time; # get the data from the form #&GetFormArgs(); $q = new CGI; # get form values & cookie values %in = (); foreach ($q->param()) { $in{$_} = $q->param($_); } @errors = (); ############################################## # constants $COUNTER_FILE = "som_counter"; $CACHE_DIR = "som_cache/"; $LOG_FILE = "som_log"; $CACHE_EXPIRATION_DAYS = 3; $SCHEDULE_OF_CLASSES_URL = "https://acis.as.cmu.edu/gale2/open/Schedule/SOCServlet"; $FIRST_CLASS_OFFSET = 700; $TIME_MULTIPLIER = 50; %DAYS = ( 'M' => 'Monday', 'T' => 'Tuesday', 'W' => 'Wednesday', 'R' => 'Thursday', 'F' => 'Friday' ); $NUM_FIELDS = 16; $EMAIL = "bb2\@andrew.cmu.edu"; %DEPARTMENTS = ( 'F02' => { '31' => 'AFR', '48' => 'ARC', '60' => 'ART', '03' => 'BSC', '42' => 'BHE', '70' => 'BA', '62' => 'CFA', '39' => 'CIT', '99' => 'CMU', '74' => 'CIL', '06' => 'CHE', '09' => 'CMY', '12' => 'CEE', '15' => 'CS', '10' => 'ALD', '51' => 'DES', '54' => 'DRA', '73' => 'ECO', '18' => 'ECE', '20' => 'IAE', '19' => 'EPP', '76' => 'ENG', '53' => 'ETC', '45' => 'IA', '46' => 'IA', '47' => 'IA', '66' => 'HSS', '67' => 'HSS', '79' => 'HIS', '05' => 'HCI', '14' => 'INI', '95' => 'IS', '11' => 'LTI', '38' => 'MCS', '91' => 'MPM', '27' => 'MSE', '21' => 'MSC', '24' => 'MEG', '30' => 'MST', '82' => 'ML', '57' => 'MUS', '32' => 'NVS', '80' => 'PHI', '69' => 'PE', '33' => 'PHY', '85' => 'PSY', '90' => 'PPM', '16' => 'ROB', '88' => 'SDS', '17' => 'SE', '36' => 'STA', }, 'S03' => { '31' => 'AFR', '48' => 'ARC', '60' => 'ART', '03' => 'BSC', '42' => 'BMD', '70' => 'BA', '62' => 'CFA', '39' => 'CIT', '99' => 'CMU', '74' => 'CIL', '06' => 'CHE', '09' => 'CMY', '12' => 'CEE', '15' => 'CS', '10' => 'ALD', '51' => 'DES', '54' => 'DRA', '73' => 'ECO', '18' => 'ECE', '20' => 'IAE', '19' => 'EPP', '76' => 'ENG', '53' => 'ETC', '45' => 'IA', '46' => 'IA', '47' => 'IA', '66' => 'HSS', '67' => 'HSS', '79' => 'HIS', '05' => 'HCI', '14' => 'INI', '95' => 'IS', '11' => 'LTI', '38' => 'MCS', '91' => 'MPM', '27' => 'MSE', '21' => 'MSC', '24' => 'MEG', '30' => 'MST', '82' => 'ML', '57' => 'MUS', '32' => 'NVS', '80' => 'PHI', '69' => 'PE', '33' => 'PHY', '85' => 'PSY', '90' => 'PPM', '16' => 'ROB', '88' => 'SDS', '17' => 'SE', '36' => 'STA', }, 'F03' => { '31' => 'AFR', '48' => 'ARC', '60' => 'ART', '03' => 'BSC', '42' => 'BMD', '70' => 'BA', '62' => 'CFA', '39' => 'CIT', '99' => 'CMU', '74' => 'CIL', '06' => 'CHE', '09' => 'CMY', '12' => 'CEE', '15' => 'CS', '10' => 'ALD', '51' => 'DES', '54' => 'DRA', '73' => 'ECO', '18' => 'ECE', '20' => 'IAE', '19' => 'EPP', '76' => 'ENG', '53' => 'ETC', '45' => 'IA', '46' => 'IA', '47' => 'IA', '66' => 'HSS', '67' => 'HSS', '79' => 'HIS', '05' => 'HCI', '14' => 'INI', '95' => 'IS', '11' => 'LTI', '38' => 'MCS', '91' => 'MPM', '27' => 'MSE', '21' => 'MSC', '24' => 'MEG', '30' => 'MST', '82' => 'ML', '57' => 'MUS', '32' => 'NVS', '80' => 'PHI', '69' => 'PE', '33' => 'PHY', '85' => 'PSY', '90' => 'PPM', '16' => 'ROB', '88' => 'SDS', '17' => 'SE', '36' => 'STA', '98' => 'STU', '96' => 'WC' }, 'S04' => { '31' => 'AFR', '48' => 'ARC', '60' => 'ART', '03' => 'BSC', '42' => 'BMD', '70' => 'BA', '62' => 'CFA', '39' => 'CIT', '99' => 'CMU', '74' => 'CIL', '06' => 'CHE', '09' => 'CMY', '12' => 'CEE', '15' => 'CS', '10' => 'ALD', '51' => 'DES', '54' => 'DRA', '73' => 'ECO', '18' => 'ECE', '20' => 'IAE', '19' => 'EPP', '76' => 'ENG', '53' => 'ETC', '45' => 'IA', '46' => 'IA', '47' => 'IA', '66' => 'HSS', '67' => 'HSS', '79' => 'HIS', '05' => 'HCI', '14' => 'INI', '95' => 'IS', '11' => 'LTI', '38' => 'MCS', '91' => 'MPM', '27' => 'MSE', '21' => 'MSC', '24' => 'MEG', '30' => 'MST', '82' => 'ML', '57' => 'MUS', '32' => 'NVS', '80' => 'PHI', '69' => 'PE', '33' => 'PHY', '85' => 'PSY', '90' => 'PPM', '16' => 'ROB', '88' => 'SDS', '17' => 'SE', '36' => 'STA', '98' => 'STU', '96' => 'WC' }, 'F04' => { '31' => 'AFR', '48' => 'ARC', '60' => 'ART', '03' => 'BSC', '42' => 'BMD', '70' => 'BA', '62' => 'CFA', '39' => 'CIT', '99' => 'CMU', '74' => 'CIL', '06' => 'CHE', '09' => 'CMY', '12' => 'CEE', '15' => 'CS', '10' => 'ALD', '51' => 'DES', '54' => 'DRA', '73' => 'ECO', '18' => 'ECE', '20' => 'IAE', '19' => 'EPP', '76' => 'ENG', '53' => 'ETC', '45' => 'IA', '46' => 'IA', '47' => 'IA', '66' => 'HSS', '67' => 'HSS', '79' => 'HIS', '05' => 'HCI', '14' => 'INI', '95' => 'IS', '11' => 'LTI', '38' => 'MCS', '91' => 'MPM', '27' => 'MSE', '21' => 'MSC', '24' => 'MEG', '30' => 'MST', '82' => 'ML', '57' => 'MUS', '32' => 'NVS', '80' => 'PHI', '69' => 'PE', '33' => 'PHY', '85' => 'PSY', '90' => 'PPM', '16' => 'ROB', '88' => 'SDS', '17' => 'SE', '36' => 'STA', '98' => 'STU', '96' => 'WC' } ); &set_colors($in{color_scheme}); ############################################## # header print "Content-Type: text/html\n\n"; $q->delete('redirect'); $q->delete('message'); foreach (keys %in) { if($in{$_} eq '') { $q->delete($_); } } $url = $q->url(-query => 1); print < Schedule
Schedule-O-Matic
(here's a link to this schedule)
disclaimer: this schedule is in no way authoritative. it is generated automatically and subject to errors.
always consult the HUB web page to double check results.

EOHTML ; ############################################# # get course information # @courses = (); $color_counter = 0; @course_inputs = (); foreach $i (1 .. $NUM_FIELDS) { push @course_inputs, $in{"c$i"}; } if($in{course_list}) { while($in{course_list} =~ s/(\d\d\d\d\d)\s*(\w+\d*)//s) { print "\n"; push @course_inputs, ($1 . $2); } } foreach $i (@course_inputs) { $this_course = &get_course_info($in{semester}, $i); if($this_course) { $this_course->{color} = $color_counter++; push @courses, $this_course; } } ############################################# # create schedule table %schedule = ( 'M' => {}, 'T' => {}, 'W' => {}, 'R' => {}, 'F' => {} ); @time_range = (&time_to_index(2400), &time_to_index(0000)); foreach $this_course (@courses) { foreach $this_section (@{ $this_course->{sections} }) { if($this_section->{start} ne '00') { foreach $this_section_day (split(//, $this_section->{days})) { foreach (&time_to_index($this_section->{start}) .. &time_to_index($this_section->{end})) { push @{ $schedule{$this_section_day}->{classes}->[$_] }, [ $this_course, $this_section ]; if($_ < $time_range[0]) { $time_range[0] = $_; } elsif ($_ > $time_range[1]) { $time_range[1] = $_; } } } } } } # figure out widths of day columns foreach $this_day (keys %schedule) { $schedule{$this_day}->{width} = 1; foreach $this_time ($time_range[0] .. $time_range[1]) { if(($temp = scalar(@{ $schedule{$this_day}->{classes}->[$this_time] })) > $schedule{$this_day}->{width}) { $schedule{$this_day}->{width} = $temp; } } } ############################################# # report errors if(@errors) { print "
\n"; print "" . (scalar(@errors) > 1 ? 'Errors have occurred:' : 'An error has occurred:') . "
\n"; foreach (@errors) { print; print "
\n"; } print "

\n"; } ############################################# # output schedule table if($in{border}) { $in{border} = 1 } else { $in{border} = 0 } if($in{cell_border}) { $in{cell_border} = 1 } else { $in{cell_border} = 0 } if(@courses) { print < EOHTML ; foreach $this_day ('M', 'T', 'W', 'R', 'F') { print "\n"; } print "\n"; foreach $this_time ($time_range[0] .. $time_range[1]) { $bg_color_toggle = !$bg_color_toggle; print "\n"; print "\n"; foreach $this_day ('M', 'T', 'W', 'R', 'F') { if($schedule{$this_day}->{classes}->[$this_time]) { $this_width = 1; foreach $this_course (@{ $schedule{$this_day}->{classes}->[$this_time] }) { foreach $scan_time (&time_to_index($this_course->[1]->{start}) .. &time_to_index($this_course->[1]->{end})) { if(($temp = scalar(@{ $schedule{$this_day}->{classes}->[$scan_time] })) > $this_width) { $this_width = $temp; } } } $course_count = $this_width; foreach $this_course (@{ $schedule{$this_day}->{classes}->[$this_time] }) { $course_count--; if($this_time == &time_to_index($this_course->[1]->{start})) { print "\n"; } } foreach (1 .. $course_count) { print "\n"; } } else { print "\n"; } } print "\n"; } print <
 \n"; print "" . $DAYS{$this_day} . "\n"; print "
" . &format_time(&index_to_time($this_time)) . "[1]->{length} ALIGN=center VALIGN=center BGCOLOR=#$CLASS_COLORS[$this_course->[0]->{color}]>"; $this_cell = ''; if($in{print_course_number}) { #if($in{course_number_link}) { #$this_cell .= "[0]->{url}', 'coursedet','resizable=yes,toolbar=yes,menubar=no,statusbar=no,directories=no,location=no,scrollbars=yes,width=500,height=300,left=10,top=20')\">"; #} $this_cell .= $this_course->[0]->{number}; if($in{course_number_link}) { $this_cell .= ""; } $this_cell .= "\n"; } if($in{print_course_name}) { if($this_cell) { $this_cell .= "
\n" } $this_cell .= $this_course->[0]->{name} . "\n"; } if($in{print_course_section}) { if($this_cell) { $this_cell .= "
\n" } $this_cell .= $this_course->[1]->{name} . "\n"; } if($in{print_course_mini} && $this_course->[1]->{mini} ne '0') { if($this_cell) { $this_cell .= "
\n" } $this_cell .= '(' . $this_course->[1]->{mini} . ")\n"; } if($in{print_course_room}) { if($this_cell) { $this_cell .= "
\n" } $this_cell .= $this_course->[1]->{room} . "\n"; } print "$this_cell
"; print " "; print ""; print " "; print "
EOHTML ; } ############################################# # output course key if($in{generate_course_key} && @courses) { @total_units = (0, 0); $last_course = ''; $show_mini = 0; foreach $this_course (@courses) { foreach $this_section (@{ $this_course->{sections} }) { if($this_section->{mini} ne '0') { $show_mini = 1; } if($this_section->{mini} eq '0') { $this_section->{mini} = ' '; } } if($this_course->{units} =~ /^[\d\.]+$/) { $total_units[0] += $this_course->{units}; $total_units[1] += $this_course->{units}; $this_course->{units} = $this_course->{units} + 0; } elsif($this_course->{units} =~ /^([\d\.]+)\-([\d\.]+)$/) { $total_units[0] += $1; $total_units[1] += $2; $this_course->{units} = ($1 + 0) . '-' . ($2 + 0); } elsif($this_course->{units} =~ /^([\d\.]+)\,([\d\.]+)$/) { $total_units[0] += $1; $total_units[1] += $2; $this_course->{units} = ($1 + 0) . ',' . ($2 + 0); } if($this_course->{units} == 0) { $this_course->{units} = ' '; } } print < 
EOHTML ; if($show_mini) { print "\n"; } print < Room EOHTML ; foreach $this_course (@courses) { my $first_section = 1; my $height = scalar(@{ $this_course->{sections} }); foreach $this_section (@{ $this_course->{sections} }) { print "\n"; if($first_section) { print "\n"; print "\n"; } print "\n"; if($show_mini) { print "\n"; } print "\n"; print "\n"; if($first_section) { print "\n"; } print "\n"; $first_section = 0; } } if($total_units[0] == $total_units[1]) { $total_units_string = $total_units[0]; } else { $total_units_string = $total_units[0] . '-' . $total_units[1]; } print "\n"; print "
# Course Name Section \n"; print "Mini\n"; print " Instructor Units
{color}]>"; #if($in{course_number_link}) { chomp $this_course->{url}; print "{url}', 'coursewin','resizable=yes,toolbars=no,menubar=no,statusbar=no,directories=no,location=no,scrollbars=yes,width=500,height=300,left=10,top=20');return false;\">"; #} print $this_course->{number}; if($in{course_number_link}) { print ""; } print "{color}]>"; print $this_course->{name}; print "{color}]>"; print $this_section->{name}; print "{color}]>"; print $this_section->{mini}; print "{color}]>"; print $this_section->{room}; print "{color}]>"; if($this_section->{instructor} !~ /^\s*$/) { print $this_section->{instructor}; } else { print " "; } print "{color}]>"; print $this_course->{units}; print "  
Total:$total_units_string  
\n"; print "
\n"; } ############################################# # footer $success = 1; open(IFILE, "$COUNTER_FILE") || ($success = 0); $count = ; close(IFILE); $count++; if($count > 1) { open(OFILE, ">$COUNTER_FILE"); print OFILE $count; close(OFILE); } if(($count % 250) == 0) { `echo \"\" | mail -s \"[SOM] $count\" $EMAIL`; `cp $COUNTER_FILE $COUNTER_FILE.bak`; } $long_count = substr('000000' . $count, -6); $time = localtime(time); #$total_time = time - $start_time; `echo \"|$long_count| $time | $ENV{REMOTE_HOST}\" >> $LOG_FILE`; print < 
The Schedule-O-Matic has been used $count times since 20 June 2002
http://live.sparkyb.net/som/
© 1999-2001 Peter Pawlowski
EOHTML ; ############################################# # subroutines sub time_to_index { (my $time) = @_; $time = substr('0000' . $time, -4); $time = substr($time, 0, 2) * 100 + (substr($time, -2) / 60) * 100; return (($time - $FIRST_CLASS_OFFSET)/$TIME_MULTIPLIER); } sub index_to_time { (my $index) = @_; $index = $index * $TIME_MULTIPLIER + $FIRST_CLASS_OFFSET; $index = substr('0' . $index, -4); my $hours = substr($index, 0, 2); my $minutes = substr('00' . (substr($index, -2) / 100) * 60, -2); return $hours . $minutes; } sub format_time { (my $time) = @_; my $hours = substr($time, 0, 2); if($hours > 12) { $hours -= 12; } else { $hours -= 0; } return $hours . ":" . substr($time, -2); } sub get_html { (my $semester, my $department) = @_; # get the text equivalent for this department so that we know which html # document to download $department_number = $department; $department = $DEPARTMENTS{$semester}->{$department}; # print "\n"; # we will return a hash containing all the courses in this department my $return_val = {}; # each department has its own cache file $cache_file = "$CACHE_DIR$department" . "_$semester"; # check to see if we've already loaded this department if($all_departments{$department}) { print "\n"; $return_val = $all_departments{$department}; # check to see if we have this department cached, only if # the user wants us to use the cache } elsif(!$in{dont_use_cache} && -e $cache_file) { # is the cache file recent enough? if((-M $cache_file) < $CACHE_EXPIRATION_DAYS && (-s $cache_file) > 0) { print "\n"; open(IFILE, $cache_file); my $current_course = {}; my $found_a_course = 0; while($line = ) { my @temp = split(/\t/, $line); if($temp[0] =~ /^\d\d\-\d\d\d$/) { $found_a_course = 1; # this is the first line of a course, save the old entry and # make a new one if(%{ $current_course }) { $return_val->{$current_course->{number}} = $current_course; } $current_course = { number => $temp[0], color => 0, name => $temp[1], units => $temp[2], sections => [], url => $temp[3] }; } else { # this is part of the current course shift @temp; push @{ $current_course->{sections} }, { name => $temp[0], mini => $temp[1], room => $temp[2], instructor => $temp[3], days => $temp[4], start => $temp[5], end => $temp[6], length => &time_to_index($temp[6] - 20) - &time_to_index($temp[5]) + 1 }; } } if(%{ $current_course }) { $return_val->{$current_course->{number}} = $current_course; } close(IFILE); if(!$found_a_course) { `echo \"\" | mail -s \"[SOM] error '$semester $department ($global_current_course, $ENV{REMOTE_HOST})'\" $EMAIL`; unlink($cache_file); $return_val = {}; } $all_departments{$department} = $return_val; } else { unlink($cache_file); } } # if we haven't gotten the information yet, we need to get it from the web page if(!%{ $return_val }) { print "\n"; # get the html my $url = "https://acis.as.cmu.edu/gale2/open/Schedule/SOCServlet?Formname=GET_CLASSES&SUBMIT=Retrieve+Schedule&SEMESTER=${semester}&GRAD_UNDER=All&MINI=NO&DEPT=${department}+"; #my $sy = "FALL"; #$sy = "SPRING" if $semester=~/^S/; #my $url = "https://acis.as.cmu.edu/open/SOC/${department}_${sy}.htm"; print "\n"; if($url =~ /^https?\:\/\/(.*?)(\:\d+)?(\/.*)$/) { my $ua = new LWP::UserAgent; # create a useragent to test $url = new URI::URL($url); my $request = new HTTP::Request('GET', $url); my $response = $ua->request($request, undef, undef); my $str = $response->as_string; #print "\n"; $str =~ s/\s*(<\/TR>)?\s*\s*/%%%%%/gis; $str =~ s/\s*<\/TR>\s*/%%%%%/gis; $str =~ s/\s*\s*/%%%%%/gis; $str =~ s/\s*\s*/~~~~~/gis; $str =~ s/<.*?>//g; $str =~ s/[\n\r]//g; $str =~ s/\ //g; # divide up into rows my @rows = split(/%%%%%/, $str); #print "\n"; # see where first column starts my $shift_number = -1; foreach $row (@rows) { @cells = split(/\s*~~~~~\s*/, $row); $i = 0; while($cells[$i] !~ /^\s*\d\d\d\d\d\s*$/ && $i < $#cells) { $i++; } if($i < $#cells) { $shift_number = $i; } if($shift_number > -1) { last; } } my $row; my $current_course = {}; foreach $row (@rows) { # split into cells my @cells = split(/\s*~~~~~\s*/, $row); # foreach (1 .. $DEPARTMENT_COLUMN_SHIFTS{$semester}->{$department}) { foreach (1 .. $shift_number) { shift @cells; } # shift @cells; @cells = @cells[0,1,4,5,6,7,8,9,10]; #print "\n"; # if the first cell is a 5 digit number, this is the first row of a class if(length($cells[0]) == 5) { # save the old entry and make a new one if(%{ $current_course }) { $return_val->{$current_course->{number}} = $current_course; } $cells[3] =~ /([\w\d]+)$/; $cells[3] = $1; if(length($cells[3]) > 1 && $cells[3] ne "Lec") { $mini = substr($cells[3], -1); } else { $mini = 0; } $url = "https://acis.as.cmu.edu/gale2/open/Schedule/SOCServlet?CourseNo=${cells[0]}&SEMESTER=${semester}&Formname=Course_Detail"; $current_course_units = $cells[2]; $current_course = { number => substr($cells[0], 0, 2) . '-' . substr($cells[0], -3), color => 0, name => $cells[1], units => $current_course_units, sections => [{ name => $cells[3], mini => $mini, room => $cells[7], instructor => $cells[8], days => $cells[4], start => &get_time($cells[5]), end => &get_time($cells[6]), length => &time_to_index(&get_time($cells[6]) - 20) - &time_to_index(&get_time($cells[5])) + 1 }], url => $url }; } else { if ($cells[3] !~ /^\s*$/) { $cells[3] =~ /([\w\d]+)$/; $cells[3] = $1; if(length($cells[3]) > 1 && $cells[3] ne "Lec") { $mini = substr($cells[3], -1); } else { $mini = 0; } } push @{ $current_course->{sections} }, { name => $cells[3], mini => $mini, room => $cells[7], instructor => $cells[8], days => $cells[4], start => &get_time($cells[5]), end => &get_time($cells[6]), length => &time_to_index(&get_time($cells[6]) - 20) - &time_to_index(&get_time($cells[5])) + 1 }; } } if(%{ $current_course }) { $return_val->{$current_course->{number}} = $current_course; } # now we need to add it to the cache open(OFILE, ">$cache_file"); foreach $this_key (keys %{ $return_val }) { $this_course = $return_val->{$this_key}; if((!$this_course->{url})) { next; } print OFILE $this_course->{number} . "\t" . $this_course->{name} . "\t" . $this_course->{units} . "\t" . $this_course->{url} . "\n"; foreach $this_section (@{ $this_course->{sections} }) { if((!$this_section->{name}) && (!$this_section->{room}) && (!$this_section->{instructor}) && (!$this_section->{days}) && (!$this_section->{start}) && (!$this_section->{end})) { next; } print OFILE "\t" . $this_section->{name} . "\t" . $this_section->{mini} . "\t" . $this_section->{room} . "\t" . $this_section->{instructor} . "\t" . $this_section->{days} . "\t" . $this_section->{start} . "\t" . $this_section->{end} . "\t\n"; } } close(OFILE); # finally, add it to our current departments $all_departments{$department} = $return_val; } } @temp = keys %{ $return_val }; return $return_val; } sub get_course_info { (my $semester, my $in_course) = @_; $global_current_course = $in_course; $in_course =~ s/\s//g; if($in_course =~ /^(\d\d)-?(\d\d\d)(.*)$/) { my $department = $1; my $course = $2; my $section = $3; $section = uc $section; $section =~ /^(.*?)(\+\d*)?(\*?)$/; $section = $1; my $lecture = $2; if(length($lecture) > 1) { $lecture = substr($lecture, 1); } my $no_units = $3; # should this be (!$section length($lecture)==0) ? if(!$section && !$lecture) { $lecture = '+'; } my $courses = &get_html($semester, $department); my $this_course = $courses->{"$department-$course"}; my $sections = []; my $current_lecture = {}; my $found_section = 0; my $section_name = ""; if(!$lecture) { $found_first_section = 0; foreach $this_section (@{ $this_course->{sections} }) { if($this_section->{name} =~ /^Lec$/) { $this_section->{name} = "0"; } if($this_section->{name} =~ /^\D/) { $found_first_section = 1; } if($this_section->{name} =~ /^\d+$/) { # print "\n"; $current_lecture = $this_section; if ($current_lecture->{name} eq "0") { $section_name = 'Lec'; } else { $section_name = 'Lec ' . $current_lecture->{name}; } } elsif(($this_section->{name} eq $section)) { # } elsif(($this_section->{name} eq $section) || # (($section eq '!' && !$found_section) && $this_section->{name})) { if(%{ $current_lecture }) { # if(($this_section->{name} =~ /^\D+$/)) { if(($this_section->{name} =~ /^\D+$/) || (substr($this_section->{name}, -1, 1) eq substr($current_lecture->{name}, -1, 1))) { if ($current_lecture->{name} eq "0") { $current_lecture->{name} = 'Lec'; } else { $current_lecture->{name} = 'Lec ' . $current_lecture->{name}; } push @{ $sections }, $current_lecture; } } $section_name = $this_section->{name};# = 'Sec ' . $this_section->{name}; push @{ $sections }, $this_section; $found_section = 1; # } elsif($found_section && $this_section->{name} eq '') { } elsif(($this_section->{name} eq '' && $section_name) && (!$found_first_section || $found_section)) { $this_section->{name} = $section_name . ' (2)'; push @{ $sections }, $this_section; } elsif($found_section) { last; } } } else { # print "\n"; foreach $this_section (@{ $this_course->{sections} }) { # print "\n"; if($this_section->{name} =~ /^Lec$/) { $this_section->{name} = "1"; } if(($this_section->{name} eq $lecture) || ($lecture eq '+' && $this_section->{name} =~ /^\d+$/)) { $this_section->{name} = 'Lec ' . $this_section->{name}; push @{ $sections }, $this_section; $section_name = $this_section->{name}; $found_section = 1; } elsif($this_section->{name} =~ /^\d+$/ && $found_section) { last; } elsif($found_section || $lecture eq '+') { if(!$this_section->{name} && $section_name) { $this_section->{name} = $section_name . ' (2)'; $section_name = $this_section->{name}; push @{ $sections }, $this_section; } elsif($this_section->{name}) { $section_name = $this_section->{name}; push @{ $sections }, $this_section; } } } } if($no_units) { $this_course->{units} = 0; } if(!@{ $sections }) { push @errors, "Couldn't find \'$department-$course $section\' in the $semester semester. First, make sure you typed the course correctly (for mini courses, make sure you type the full section name). Also make sure the course is actually offered (the HUB). Email me if you can't figure out why it won't work."; # `echo \"\" | mail -s \"[SOM] error '$in_course' $ENV{REMOTE_HOST}\" $EMAIL`; } else { $this_course->{sections} = $sections; return $this_course; } } else { if($in_course) { push @errors, "The course '$in_course' is not a valid course. Please double check the instructions and try again."; } } } sub set_colors { ($color_scheme) = @_; if($color_scheme eq 0) { # bg color for structure $STRUCTURE_BG_COLOR = "000000"; # bg colors for empty cells @EMPTY_COLORS = ("F0F0F0", "E0E0E0"); # bg color for time cells at left @TIME_BG_COLORS = ("EEEEEE", "CCCCCC"); $TIME_TEXT_COLOR = "000000"; # bg color for day cells at top $HEADING_BG_COLOR = "000000"; $HEADING_TEXT_COLOR = "FFFFFF"; @CLASS_COLORS = ( "8FA7D1", "96C79A", "FFF09E", "FDCA8A", "FF6565", "8F92C0", "A0A0A0", "BBBBBB", "B0B0B0", # 9 "AAAAAA", "C0C0C0", "CCCCCC", "AAAAAA", "AAAAAA", "AAAAAA", "AAAAAA" ); } elsif($color_scheme eq 1) { # bg color for structure $STRUCTURE_BG_COLOR = "000000"; # bg colors for empty cells @EMPTY_COLORS = ("F0F0F0", "E0E0E0"); # bg color for time cells at left @TIME_BG_COLORS = ("DDDDDD", "CCCCCC"); $TIME_TEXT_COLOR = "000000"; # bg color for day cells at top $HEADING_BG_COLOR = "000000"; $HEADING_TEXT_COLOR = "FFFFFF"; @CLASS_COLORS = ( "F0F0F0", "E0E0E0", "D0D0D0", "C0C0C0", "B0B0B0", "A0A0A0", "909090", "808080", "999999", # 9 "A9A9A9", "B9B9B9", "C9C9C9", "D9D9D9", "E9E9E9", "F9F9F9", "AAAAAA" ); } elsif($color_scheme eq 2) { # bg color for structure $STRUCTURE_BG_COLOR = "000000"; # bg colors for empty cells @EMPTY_COLORS = ("FFFFFF", "FFFFFF"); # bg color for time cells at left @TIME_BG_COLORS = ("FFFFFF", "FFFFFF"); $TIME_TEXT_COLOR = "000000"; # bg color for day cells at top $HEADING_BG_COLOR = "FFFFFF"; $HEADING_TEXT_COLOR = "000000"; @CLASS_COLORS = ( "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF" ); } } sub get_time { (my $time) = @_; $return_val = ""; $time =~ /^(\d\d):(\d\d)(\w\w)$/; $return_val = substr('00' . ($1 + (($3 eq 'PM') && ($1 ne '12') ? 12 : 0)), -2) . $2; return $return_val; }