Files
@ b5c4b3fbe060
Branch filter:
Location: SlatePermutate/school.d/dordt.crawl.inc
b5c4b3fbe060
7.6 KiB
text/x-povray
Add support for Dordt College.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | <?php /* -*- mode: php; -*- */
/*
* Copyright 2012 Nathan Phillip Brink <ohnobinki@ohnopublishing.net>
*
* This file is a part of slate_permutate.
*
* slate_permutate is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* slate_permutate is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with slate_permutate. If not, see <http://www.gnu.org/licenses/>.
*/
function dordt_crawl_semester_list(array $school, array &$semesters, &$school_crawl_log)
{
$cookies = array();
$uri = $school['url'] . 'academics/course_schedules/';
$semesters_html = school_crawl_geturi($uri, $cookies, $school_crawl_log);
$semesters_dom = new DOMDocument();
$semesters_dom->loadHTML($semesters_html);
$semesters_xpath = new DOMXPath($semesters_dom);
$seasons_map = array(
'S' => 'spring',
'F' => 'fall',
);
foreach ($semesters_xpath->query('//a[contains(@href, "course_list.pl?")]') as $a_node)
{
$q = array();
list(, $href_querystring) = explode('?', $href = $a_node->getAttribute('href'));
foreach (explode('&', $href_querystring) as $href_query_namevalue)
{
list($name, $value) = explode('=', $href_query_namevalue, 2);
$q[$name] = $value;
}
if (empty($q['year'])
|| empty($q['sem']))
{
school_crawl_logf($school_crawl_log, 2, "Unable to parse URI's GET arguments into year and sem parts: %s", $href);
continue;
}
if (empty($seasons_map[$q['sem']]))
{
school_crawl_logf($school_crawl_log, 2, "Unable to parse season `%s' into season for `%s': %s",
$q['sem'], $a_node->textContent, $href);
continue;
}
$semesters[] = new Semester($q['year'], $seasons_map[$q['sem']]);
}
return 0;
}
function dordt_crawl_semester(array $school, Semester $semester, &$school_crawl_log)
{
$seasons_map = array(
'spring' => 'S',
'fall' => 'F',
);
if (empty($seasons_map[$semester->season_get()]))
{
school_crawl_logf($school_crawl_log, 2, "Unable to understand season %s.", $semester->season_get());
return 1;
}
$cookies = array();
$uri = $school['url'] . 'academics/course_schedules/';
$semesters_html = school_crawl_geturi($uri, $cookies, $school_crawl_log);
$semesters_dom = new DOMDocument();
$semesters_dom->loadHTML($semesters_html);
$semesters_xpath = new DOMXPath($semesters_dom);
$semester_href = NULL;
foreach ($semesters_xpath->query('//a[contains(@href, "course_list.pl?") and contains(@href, "sem=' . $seasons_map[$semester->season_get()] . '") and contains(@href, "year=' . $semester->year_get() . '")]') as $a_node)
$semester_href = $a_node->getAttribute('href');
if ($semester_href === NULL)
{
school_crawl_logf($school_crawl_log, 4, "Unable to find link associated with schedule's semester");
return 1;
}
$uri = school_crawl_url($uri, $semester_href);
$semester_html = school_crawl_geturi($uri, $cookies, $school_crawl_log);
$semester_dom = new DOMDocument();
$semester_dom->loadHTML($semester_html);
$semester_xpath = new DOMXPath($semester_dom);
foreach ($semester_xpath->query('//ul[contains(concat(" ", normalize-space(@class), " "), " columns ")]//a[contains(@href, "#")]')
as $a_node)
{
/* <li><a href="#ASK">Academic Skills</a></li> */
list(, $hash) = explode('#', $a_node->getAttribute('href'));
$semester->department_name_set($hash, $a_node->textContent);
}
$labs = array();
foreach ($semester_xpath->query('//table[contains(concat(" ", normalize-space(@class), " "), " schedule ")]') as $table_schedule)
{
$head_tr = NULL;
foreach ($semester_xpath->query('.//thead//tr', $table_schedule) as $head_tr)
break;
if ($head_tr === NULL)
{
school_crawl_logf($school_crawl_log, 4, "Unable to find headings for some table.");
continue;
}
$column_mapping = array(
'DEPT' => FALSE,
'NUM' => FALSE,
'SEC' => FALSE, /* section */
'TITLE' => FALSE,
'CR' => FALSE, /* credits */
'RM' => FALSE, /* room */
'INSTRUCTOR' => FALSE,
);
$willy = FALSE;
foreach ($column_mapping as $name => $false)
if (($column_mapping[$name] = school_crawl_table_resolve_column($head_tr, $name)) === FALSE)
{
school_crawl_logf($school_crawl_log, 4, "Unable to resolve column %s.", $name);
$willy = TRUE;
break;
}
if ($willy)
continue;
/*
* <tr>
* <td>AGRI</td>
* <td>111L</td>
* <td>01</td>
* <td>Agri 111 Lab</td>
* <td>0.00</td>
* <td colspan="2" style="text-align: right;">De Vries, G</td>
* </tr>
* <tr>
* <td colspan="3"></td>
* <td colspan="2">2:00 PM - 5:00 PM, W</td>
* <td colspan="2" align="left" valign="top">SB 138</td>
* </tr>
*/
foreach ($semester_xpath->query('.//tbody//tr', $table_schedule) as $tr_row)
{
$rownodes = school_crawl_table_rownodes($tr_row);
$new_dept = school_crawl_table_rownode_index($rownodes, $column_mapping['DEPT'])->textContent;
if (!empty($new_dept))
{
$course = school_crawl_table_rownode_index($rownodes, $column_mapping['NUM'])->textContent;
$section = school_crawl_table_rownode_index($rownodes, $column_mapping['SEC'])->textContent;
$title = school_crawl_table_rownode_index($rownodes, $column_mapping['TITLE'])->textContent;
$credits = school_crawl_table_rownode_index($rownodes, $column_mapping['CR'])->textContent;
$instructor = school_crawl_table_rownode_index($rownodes, $column_mapping['INSTRUCTOR'])->textContent;
$dept = $new_dept;
}
else
{
if (empty($dept))
{
school_crawl_logf($school_crawl_log, 6, "Unexpected empty DEPT column");
continue;
}
$room = school_crawl_table_rownode_index($rownodes, $column_mapping['RM'])->textContent;
$timestuff = school_crawl_table_rownode_index($rownodes, $column_mapping['TITLE'])->textContent;
/*
* 2:00 PM - 5:00 PM, W
* 1:00 PM - 1:50 PM, M/W/F
* 2:00 PM - 5:00 PM, T
* 1:50 PM - 4:50 PM, Th
* 8:00 AM - 9:15 AM, T/Th
*/
if (!preg_match('/(\\d*:\\d* .M) - (\\d*:\\d* .M), (.*)/', $timestuff, $matches))
{
school_crawl_logf($school_crawl_log, 7, "Unable to parse timestuff: %s",
$timestuff);
continue;
}
$time_start = school_crawl_time_format(strptime($matches[1], '%l:%M %p'));
$time_end = school_crawl_time_format(strptime($matches[2], '%l:%M %p'));
$days = school_crawl_days_format($school_crawl_log, explode('/', $matches[3]));
school_crawl_logf($school_crawl_log, 1, "Adding %s", $dept . '-' . $course . '-' . $section);
$semester->section_add($dept, $course, new Section($section, array(new SectionMeeting($days, $time_start, $time_end, $room, 'lecture', $instructor)), NULL, $credits), $title);
/* Save labs for dependency generation later */
if (preg_match('/L$/', $course))
{
$labs += array($dept => array());
$labs[$dept][$course] = TRUE;
}
}
}
}
/* Bind lab dependencies */
foreach ($labs as $dept => $courses)
{
foreach ($courses as $course => $true)
{
$course_base = $semester->class_get($dept, substr($course, 0, strlen($course) - 1));
if (!empty($course_base))
$course_base->dependency_add($semester->class_get($dept, $course));
}
}
}
|