public function getSectionSelect() { $this->ensureConsistency(); $sections = SectionQuery::create()->filterByCourse($this)->orderBy('Section.Num', 'asc')->find(); $r = array(); foreach ($sections as $s) { $r[] = array('professor' => $s->getProfessor(), 'id' => $s->getSlug(), 'number' => $s->getNum()); } return $r; }
/** * Gets the number of Section objects related by a many-to-many relationship * to the current object by way of the section_has_item cross-reference table. * * @param Criteria $criteria Optional query object to filter the query * @param boolean $distinct Set to true to force count distinct * @param PropelPDO $con Optional connection object * * @return int the number of related Section objects */ public function countSections($criteria = null, $distinct = false, PropelPDO $con = null) { if (null === $this->collSections || null !== $criteria) { if ($this->isNew() && null === $this->collSections) { return 0; } else { $query = SectionQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByItem($this)->count($con); } } else { return count($this->collSections); } }
public function sendPage() { global $app, $siteName, $siteUrl; $args = func_get_args(); if (count($args) == 6) { list($fromEmail, $toEmail, $school, $campus, $term, $id) = $args; } else { $campus = null; list($fromEmail, $toEmail, $school, $term, $id) = $args; } if (!($this->validate($fromEmail) && $this->validate($toEmail))) { echo "false"; return; } $s = SectionQuery::create()->filterBySlug($id)->filterByTermSlug($term); if ($campus) { $s->filterByCampusSlug($campus); } $s = $s->filterBySchoolSlug($school)->findOne(); $courseName = $s->getName(); $subject = "Textbooks for {$courseName}"; $in['ids'] = $id; $in['school'] = $school; $in['campus'] = $campus; $in['term'] = $term; if (!$school || $school == 'isbn') { $route = 'isbn_results'; } else { if ($campus) { $route = 'multicampus_results'; } else { $route = 'singlecampus_results'; } } $url = $app->request()->getUrl() . $app->urlFor($route, $in) . '?saved'; $date = date('l, F j'); $body = <<<END {$fromEmail} has sent you a link to view all of the textbooks for {$courseName} on {$siteName}: {$url} {$siteName} is a free, student-run service that finds college students' textbooks at the cheapest prices. You tell us your courses and we'll find your books at the lowest prices. It's that easy. -- You're receiving this email because on {$date}, someone visited {$siteUrl} and told us you'd like a link to this course's books. If you feel you received this message in error, let us know by replying to this message. We'll make sure it doesn't happen again. END; try { $this->sendMail($toEmail, $subject, $body, $fromEmail, $fromEmail); echo "true"; } catch (Exception $e) { echo "false"; throw $e; } }
//var_dump($result); //die(); preg_match_all("/header\"\\>(.+?)\\</", $result, $matches); $matches = $matches[1]; print_r($matches); for ($i = 0; $i < count($matches); $i += 11) { $num = substr($matches[$i], strpos($matches[$i], '0'), 6); $section = curl_get("http://voyager.adminsvc.temple.edu/tucourses/tu_coursesdescrip.asp?name={$num}&Clear=Yes"); if (preg_match("/Instructor.+?descripNobold\"\\>([^<]+?),([^<]+?)\\</s", $section, $m)) { $prof = trim(preg_replace("/\\s+/", ' ', $m[2] . $m[1])); } else { $prof = null; } $cnum = ltrim($matches[$i + 1], '0'); $snum = $matches[$i + 3]; $cname = formatCourseName($matches[$i + 4]); $course = CourseQuery::create()->filterByDept($dept)->filterByNum($cnum)->findOne(); if ($course) { echo "setting {$cname}\n"; $course->setName($cname)->save(); if ($prof) { $section = SectionQuery::create()->filterByCourse($course)->filterByNum($snum)->findOne(); if ($section) { echo $prof . "\n"; $section->setProfessor($prof)->save(); } } } } } }
public function getRoot() { return SectionQuery::create()->findRoot($this->getId()); }
<?php /** * fix-slugs [SCHOOL=all] * * Regenerate section slugs and full names. */ $sections = SectionQuery::create(); if (isset($argv[1]) && $argv[1] != 'all') { $sections->filterBySchoolSlug($argv[1]); } foreach ($sections->find() as $s) { $s->save(); }
function updateCoursesAndSectionsNew() { global $courses; //need the dot instead of a more specific dash because there's a unicode dash occasionally $time = "/\\s*\\d{1,2}\\:\\d{1,2}\\s*.?\\s*\\d{1,2}\\:\\d{1,2}\\s*[paPA][mM]\\s*/"; //echo preg_match($time, "10:10 – 11:30 am"); $base = "http://inside.bard.edu/academic/courses/current/"; $pages = array("anthropology", "lit2courses", "music", "physics", "barc", "arthistory", "dance", "film", "photography", "studioart", "theater", "sequence", "writers", "lit3courses", "arabic", "chinese", "classic", "greek", "latin", "sanskrit", "french", "german", "hebrew", "italian", "japanese", "russian", "spanish", "biology", "chemistry", "computer", "mathematics", "hpsscience", "economics", "bgia", "history", "philosophy", "politicalstudies", "psychology", "religion", "socialstudies", "sociology", "amstudies", "asian_studies", "classic", "fstudies", "gstudies", "hrp", "istudies", "restudies", "sts", "sstudies", "africana", "cogsci", "envstudies", "gss", "gis", "hrp", "ics", "js", "lais", "meds", "middleeast.htm", "spolicy", "socialstudies", "sre", "theology", "vs"); foreach ($pages as $p) { $result = file_get_contents($base . $p . (preg_match("/\\.htm/", $p) ? "" : ".html")); $dom = new DOMDocument(); @$dom->loadHTML($result); $xpath = new DOMXPath($dom); $trs = $xpath->query('//tr'); foreach ($trs as $tr) { var_dump($tr); $professor = (string) current($xpath->query('/td[2]/p/b[0]', $tr)); echo $professor; $course = (string) current($xpath->query('/td[1]/p[0]/b/span', $tr)); $courseParts = explode(" ", $course); $name = (string) current($xpath->query('/td[1]/p[0]/b/span/span[1]', $tr)); $name .= (string) current($xpath->query('/td[1]/p[1]/b/span', $tr)); $course = CourseQuery::create()->filterByNum($courseParts[1])->useDeptQuery()->filterByAbbr($courseParts[0])->useTermQuery()->useCampusQuery()->useSchoolQuery()->filterBySlug('bard')->endUse()->endUse()->endUse()->endUse()->findOne(); if ($course) { $course->setName($name)->save(); $sections = SectionQuery::create()->filterByCourseId($course->getId()); if ($professor && $sections->keepQuery()->count() > 1) { foreach ($sections->find() as $s) { $s->reload()->setProfessor($professor)->save(); } } } } return; ////// $rows = explode("<tr", $result); unset($rows[0]); foreach ($rows as $r) { preg_match_all("/\\>\\s*([^\\>\\<]*[A-Za-z]+[^\\>\\<]*)\\s*\\</", $r, $matches, PREG_SET_ORDER); foreach ($matches as &$m) { $m = $m[1]; } reset($matches); preg_match("/\\s([A-Z]+)\\s*(\\d+)/", " " . $matches[0], $details); $deptAbbr = $details[1]; $courseNum = $details[2]; $hasSection = preg_match("/^[A-Z]+\$/", $matches[1], $sectionMatches); $sectionNum = $hasSection ? $sectionMatches[0] : "1"; $timeIndex = false; $timeCount = 0; foreach ($matches as $i => $m) { if (preg_match($time, $m)) { //echo "<b>$m</b>"; if (!$timeIndex) { $timeIndex = $i; } $timeCount++; } else { if (preg_match("/Lab\\s[A-Z]|\\(Lecture|Burton\\sBrody/", $m)) { echo "aa"; $timeCount++; } } } echo $timeIndex; echo $timeCount; $professor = $matches[2 + (int) $hasSection]; $courseName = $hasSection ? $matches[2] : $matches[1]; if ($timeIndex > 4 + (int) $hasSection + ($timeCount - 1)) { $courseName .= " " . $matches[2 + (int) $hasSection]; } $courseName = trim(preg_replace("/\\s+/", " ", $courseName)); $professor = preg_replace("/\\s+/", " ", $professor); if ($professor) { $courseName = str_replace(trim($professor), "", $courseName); } $courseName = trim(preg_replace("/:\\s*\$/", "", $courseName)); $course = CourseQuery::create()->filterByNum($courseNum)->useDeptQuery()->filterByAbbr($deptAbbr)->useTermQuery()->useCampusQuery()->useSchoolQuery()->filterBySlug('bard')->endUse()->endUse()->endUse()->endUse()->findOne(); if ($course) { $course->setName($courseName)->save(); $section = SectionQuery::create()->filterByCourse($course)->findOne(); if ($section && $professor) { $section->setProfessor($professor)->save(); } $sections = SectionQuery::create()->filterByCourse($course)->find(); foreach ($sections as $section) { $section->setName($section->makeName())->save(); } } } //die(); } foreach ($courses as $key => $name) { preg_match("/([^\\d]+)(.+)/", $key, $matches); print_r($matches); if ($key == 'FYSFSEM') { $matches[1] = 'FYS'; $matches[2] = 'FSEM'; } if ($key == 'FYSADD ON') { $matches[1] = 'FYS'; $matches[2] = 'ADD ON'; } $course = CourseQuery::create()->filterByNum($matches[2])->useDeptQuery()->filterByAbbr($matches[1])->useTermQuery()->useCampusQuery()->useSchoolQuery()->filterBySlug('bard')->endUse()->endUse()->endUse()->endUse()->findOne(); if ($course) { $course->setName($name)->save(); } } }
/** * Get the associated Section object * * @param PropelPDO Optional Connection object. * @return Section The associated Section object. * @throws PropelException */ public function getSection(PropelPDO $con = null) { if ($this->aSection === null && ($this->section_b_id !== "" && $this->section_b_id !== null)) { $this->aSection = SectionQuery::create()->filterBySectionMetadata($this)->findOne($con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aSection->addSectionMetadatas($this); */ } return $this->aSection; }
function render() { global $vendors; $args = func_get_args(); if (count($args) == 1) { $school = $campus = $term = null; $ids = $args[0]; } else { if (count($args) == 4) { $school = $args[0]; $campus = $args[1]; $term = $args[2]; $ids = isset($args[3]) ? $args[3] : null; } else { $school = $args[0]; $campus = null; $term = $args[1]; $ids = isset($args[2]) ? $args[2] : null; } } if (defined('EMERGENCY') && $school) { $this->redirect_to_index(); } if (!$school) { $isbnMode = true; unset($vendors[array_search('Bookstore', $vendors)]); $schoolSlug = $campusSlug = $termSlug = false; } else { $isbnMode = false; $school = School::findOneBySlug($school); if (!$school) { $this->redirect_to_index(); } $vendors[array_search('Bookstore', $vendors)] = $school->getBookstoreType(); $schoolSlug = $school->getSlug(); if ($campus) { $campus = CampusQuery::create()->filterBySchool($school)->filterBySlug($campus)->findOne(); if (!$campus) { $this->redirect_to_index(); } $campusSlug = $campus->getSlug(); } else { $campusSlug = false; } $q = TermQuery::create(); if ($campus) { $q->filterByCampus($campus); } else { $q->useCampusQuery()->filterBySchool($school)->endUse(); } $term = $q->filterBySlug($term)->findOne(); if (!$term) { $this->redirect_to_index(); } $termSlug = $term->getSlug(); $termName = $term->getName(); } $this->setTitle('Your Books'); $this->inlineJS[] = "Globals.SECTION_DELIMITER = '" . SECTION_DELIMITER . "';"; $this->inlineJS[] = "Globals.SCHOOL_SLUG = " . ($schoolSlug ? "'{$schoolSlug}'" : "false") . ";"; $this->inlineJS[] = "Globals.CAMPUS_SLUG = " . ($campusSlug ? "'{$campusSlug}'" : "false") . ";"; $this->inlineJS[] = "Globals.TERM_SLUG = " . ($termSlug ? "'{$termSlug}'" : "false") . ";"; $this->inlineJS[] = "Globals.IDS = '{$ids}';"; $this->inlineJS[] = "Globals.THIS_PAGE_URL = '" . CURRENT_URL . "';"; $this->overrideAnalyticsPageUrl("results"); // If only one section, use its title as a FB Open Graph title (for share functionality) if ($school) { $sections = SectionQuery::create()->filterBySlug($ids)->filterBySchoolSlug($schoolSlug)->filterByTermSlug($termSlug); if ($campusSlug) { $sections->filterByCampusSlug($campusSlug); } $sections = $sections->find(); if ($sections->count() == 1) { $courseName = $sections[0]->getName(); $shortName = $school->getShortName(); $term = $term->getName(); global $siteName; $this->misc[] = "<meta property='og:title' content='{$courseName} › {$shortName} {$siteName} ({$termName})' />"; } } if ($isbnMode) { $hashPrefix = ""; } else { if ($campusSlug) { $hashPrefix = "{$campusSlug}/{$termSlug}/"; } else { $hashPrefix = "{$termSlug}/"; } } $this->renderPage('results', array('isbnMode' => $isbnMode, 'breadcrumbFormat' => 'results', 'schoolSlug' => $schoolSlug, 'ids' => $ids, 'hashPrefix' => $hashPrefix, 'tableClass' => 'vendor' . count($vendors), 'resultsURL' => '')); }
<?php require_once __DIR__ . "/../../base/propel.php"; require_once __DIR__ . "/../../spider/curl.php"; $term = "2011_1"; $school = SchoolQuery::create()->filterBySlug('columbia')->findOne(); $sections = SectionQuery::create()->joinWith('Section.Course')->joinWith('Course.Dept')->filterBySchool($school)->orderBy('Section.Slug')->find(); $sections->populateRelation('SectionHasItem'); foreach ($sections as $section) { $itemsByAuthor = array(); foreach ($section->getSectionHasItems() as $shi) { $itemsByAuthor[trim(strtolower($shi->getItem()->getAuthor()))] = $shi->getItem(); } echo $section->getSlug() . ", number of items in db : " . count($itemsByAuthor) . "\n"; $url = "https://courseworks.columbia.edu/cms/public/intro_out.cfm?crs=" . $section->getCourse()->getDept()->getAbbr() . $section->getCourse()->getNum() . '_' . $section->getNum() . '_' . $term; $result = curl_get($url); preg_match_all("/\\<tr.*?\\>.*?\\<\\/tr\\>/s", $result, $matches); $idsAlreadyTaken = array(); $requireType = null; foreach ($matches[0] as $match) { if (preg_match("/\\<strong\\>(.*?)\\<\\/strong\\>/", $match, $ms)) { if ($ms[1] == "Recommended") { $requireType = SectionHasItem::REQUIRED; } else { if ($ms[1] == "Required") { $requireType = SectionHasItem::RECOMMENDED; } } } if (preg_match_all("/\\<td.*?\\>(.*?)\\<\\/td\\>/", $match, $ms)) { if (count($ms[1]) != 7) {
preg_match_all($regex2, $result, $matches, PREG_SET_ORDER); } if (count($matches) > 1) { unset($matches[0]); } if (!$matches) { echo "No matches for {$schoolNum} {$abbr}.\n"; } foreach ($matches as $m) { $dept = $m[1]; $course = $m[2]; $section = $m[3]; $name = trim($m[4]); $professor = trim($m[5]); echo "{$dept}{$course}{$section} "; $s = SectionQuery::create()->filterByNum($section)->useCourseQuery()->filterByNum($course)->useDeptQuery()->filterByAbbr($dept)->useTermQuery()->filterByName($currentTerm)->useCampusQuery()->filterBySchool($bc)->endUse()->endUse()->endUse()->endUse()->findOne(); if (!$s) { echo "Error.\n"; } else { $c = $s->getCourse(); $d = $c->getDept(); $d->setName($formatted)->save(); if ($name && $name != ' ') { $c->setName($name)->save(); } else { $c->setName(null)->save(); } $s->reload(); if ($professor && $professor != ' ') { $s->setProfessor($professor); } else {
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(SectionPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = SectionQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
protected static function getAllSections($query, $schoolSlug, $termSlug, $campusSlug = '') { $sections = SectionQuery::create()->filterByName("%{$query}%")->filterBySchoolSlug($schoolSlug)->filterByTermSlug($termSlug); if ($campusSlug) { $sections->filterByCampusSlug($campusSlug); } $sections = $sections->join('Section.Course')->join('Course.Dept')->withColumn('Course.Num', 'CourseNum')->withColumn('Course.Name', 'CourseName')->withColumn('Dept.Abbr', 'DeptAbbr')->withColumn('Dept.Name', 'DeptName')->withColumn('LPAD(Course.Num, 6, "0")', 'PaddedCourseNum')->orderBy('DeptAbbr', 'ASC')->orderBy('PaddedCourseNum', 'ASC')->find(); $rows = array(); foreach ($sections as $s) { $rows[$s->getSlug()] = array('sectionNum' => $s->getNum(), 'courseNum' => $s->getCourseNum(), 'deptAbbr' => $s->getDeptAbbr(), 'deptName' => $s->getDeptName(), 'slug' => $s->getSlug(), 'name' => $s->getCourseName(), 'displayName' => $s->getName()); } return $rows; }
$courses = CourseQuery::create()->filterBySchool($school)->find(); foreach ($courses as $c) { $courseString = $c->getDept()->getAbbr() . $c->getNum(); $url = "http://www.clarku.edu/academiccatalog/courseQ.cfm?num={$courseString}&lookup=1&refcode=" . str_pad($c->getNum(), 3, '0', STR_PAD_LEFT); if (preg_match("/{$courseString}.*?\\s-\\s(.+)\\<\\/h1/s", curl_get($url), $matches)) { $name = preg_replace("/\\/[^\\/]+\$/", '', $matches[1]); $name = preg_replace("/Lecture|Discussion/", "", $name); $c->setName(trim($name))->save(); } } // update sections $depts = DeptQuery::create()->filterBySchool($school)->find(); foreach ($depts as $d) { $result = curl_get("http://www.clarku.edu/offices/src/courses/courselist{$term}.cfm?listsubject=" . $d->getAbbr()); $regex = "/\\<td\\>.+?\\<\\/td\\>.+?\\<td\\>.+?\\<\\/td\\>.+?\\<td\\>(.+?)\\<\\/td\\>.+?\\<td\\>.+?coursenum\\=(.+?)&refcode=(.+?)\"\\>.*?\\<td\\>.*?\\<td\\>[\\d\\s.]*?\\<\\/td\\>.*?\\<td\\>.*?\\<td\\>.*?\\<td\\>(.+?)\\<\\/td\\>.+?\\<td\\>.+?\\<\\/td\\>.+?\\<td\\>.+?\\<td\\>.+?\\<\\/tr\\>/s"; preg_match_all($regex, $result, $matches, PREG_SET_ORDER); unset($matches[0]); foreach ($matches as $m) { $prof = trim($m[4]); $dept = trim($m[3]); $cnum = trim(substr($m[2], strpos($dept, $m[2]) + strlen($dept))); $snum = trim($m[1]); if (preg_match("/\\<a name\\=\".+\"\\>(.+)\\<\\/a\\>/", $snum, $foo)) { $snum = $foo[1]; } $section = SectionQuery::create()->filterByNum($snum)->useCourseQuery()->filterByNum($cnum)->useDeptQuery()->filterBySchool($school)->filterByAbbr($dept)->endUse()->endUse()->findOne(); if ($section && $prof != "Staff") { $section->setProfessor($prof)->save(); } } }
/** * Finds the related Section objects and keep them for later * * @param PropelPDO $con A connection object */ protected function findRelatedSections($con) { $criteria = clone $this; if ($this->useAliasInSQL) { $alias = $this->getModelAlias(); $criteria->removeAlias($alias); } else { $alias = ''; } $this->sections = SectionQuery::create()->joinSectionHasItem($alias)->mergeWith($criteria)->find($con); }
protected function spiderSections() { // used by Bookstores to construct Combo urls global $sections; $sections = SectionQuery::create()->filterBySchoolSlug($this->schoolSlug)->filterByTermSlug($this->termSlug)->filterBySlug($this->sectionSlugs); if ($this->campusSlug) { $sections->filterByCampusSlug($this->campusSlug); } $sections = $sections->find(); if ($this->numSections = count($sections)) { $bookstoreClass = $this->bookstore; $bookstore = new $bookstoreClass(); $bookstore->spiderSections($sections, false); } }
public function updateSections($catalog, $sections = null) { decho("Updating sections... "); if (!$sections) { $sections = $catalog->getAllSections(); } // if metadata provider doesn't do mass section lookup if (!$sections) { $query = $this->filterByCatalog(new DeptQuery(), $catalog); $sections = array(); foreach ($query->find() as $dept) { if ($data = $catalog->getSectionsByDept($dept->getAbbr())) { $foo = array(); foreach ($data as $section) { $section['DeptAbbr'] = $dept->getAbbr(); $foo[] = $section; } $sections = array_merge($sections, $foo); } } } // if metadata provider doesn't do per-department section lookup either if (!$sections) { $query = CourseQuery::create()->join('Course.Dept')->withColumn('Dept.Abbr', 'DeptAbbr')->useDeptQuery(); $query = $this->filterByCatalog($query, $catalog)->endUse(); $sections = array(); foreach ($query->find() as $c) { if ($data = $catalog->getSectionsByCourse($c->getDeptAbbr(), $c->getNum())) { $foo = array(); foreach ($data as $section) { $section['DeptAbbr'] = $c->getDeptAbbr(); $section['CourseNum'] = $c->getNum(); $foo[] = $section; } $sections = array_merge($sections, $foo); } } } // if metadata provider doesn't do per-course section lookup either if (!$sections) { $query = SectionQuery::create()->join('Section.Course')->join('Course.Dept')->withColumn('Course.Num', 'CourseNum')->withColumn('Dept.Abbr', 'DeptAbbr')->useCourseQuery()->useDeptQuery(); $query = $this->filterByCatalog($query, $catalog)->endUse()->endUse(); $sections = array(); foreach ($query->find() as $s) { if ($data = $catalog->getSection($s->getDeptAbbr(), $s->getCourseNum(), $s->getNum())) { $data['DeptAbbr'] = $s->getDeptAbbr(); $data['CourseNum'] = $s->getCourseNum(); $sections[] = $data; } } } // if metadata provider doesn't do single section lookup either if (!$sections) { decho("fail\n"); } else { $depts = array(); $courses = array(); foreach ($sections as $section) { $s = SectionQuery::create()->filterByNum($section['Num'])->useCourseQuery()->filterByNum($section['CourseNum'])->useDeptQuery()->filterByAbbr($section['DeptAbbr']); $s = $this->filterByCatalog($s, $catalog)->endUse()->endUse()->findOne(); if (!$s) { decho("Unknown section: {$section['DeptAbbr']}:" . "{$section['CourseNum']}: {$section['Num']}\n"); } else { $s->setProfessor($section['Professor'])->save(); } if (isset($section['DeptName']) && $section['DeptName']) { $depts[] = array('Abbr' => $section['DeptAbbr'], 'Name' => $section['DeptName']); } if (isset($section['CourseName']) && $section['CourseName']) { $courses[] = array('DeptAbbr' => $section['DeptAbbr'], 'Num' => $section['CourseNum'], 'Name' => $section['CourseName']); } } decho("success\n"); if ($depts) { $this->updateDepts($catalog, $depts); } if ($courses) { $this->updateCourses($catalog, $courses); } } }
} } } $keySem = '20114'; echo "updating courses.\n"; $courses = CourseQuery::create()->filterBySchool($school)->find(); foreach ($courses as $c) { $courseKey = urlencode($c->getDept()->getAbbr() . ' ' . $c->getNum()); $url = "http://www.bu.edu/link/bin/uiscgi_studentlink.pl/1280445488?ModuleName=course_desc/start.pl&CourseKey={$courseKey}&KeySem={$keySem}"; $result = curl_get($url); if (preg_match("/Title:\\<\\/TH\\>\\s*\\<TD\\>(.+?)\\<\\/TD\\>/", $result, $matches)) { $c->setName(trim($matches[1]))->save(); } } echo "updating sections.\n"; $sections = SectionQuery::create()->filterBySchool($school)->find(); foreach ($sections as $s) { $deptAbbr = $s->getCourse()->getDept()->getAbbr(); $courseNum = $s->getCourse()->getNum(); $sectionNum = $s->getNum(); if (preg_match("/([A-Z]+)\\s([A-Z]+)/", $deptAbbr, $matches)) { $url = "http://www.bu.edu/link/bin/uiscgi_studentlink/1280538735?ModuleName=univschr.pl&SearchOptionDesc=Class+Number" . " &SearchOptionCd=S&KeySem={$keySem}&College={$matches[1]}&Dept={$matches[2]}&Course=" . "{$courseNum}&Section={$sectionNum}"; $result = curl_get($url); $regex = "/" . str_replace(" ", " ", "{$deptAbbr}{$courseNum} {$sectionNum}") . preg_quote("</a></font></td>", "/") . "\\s*" . preg_quote("<td><font size=-1 color=#330000 face=\"Verdana, Helvetica, Arial, sans-serif\">", "/") . "[^\\<]*" . preg_quote("<br>", "/") . "(\\<A[^\\<]*\\>)?" . "([^\\<]*)" . "(\\<\\/A\\>)?" . preg_quote("</font>", "/") . "/s"; if (preg_match($regex, $result, $matches)) { if ($matches[2] != "TBA") { $s->setProfessor($matches[2])->save(); } } } }
$dept = DeptQuery::create()->filterBySchool($school)->filterByAbbr($m[2])->findOne(); if ($dept) { $dept->setName($m[3])->save(); } $url = "https://banner-as1.admin.wpi.edu" . $m[1]; $result = curl_get($url); /* <TD><A HREF="http://www.wpi.edu/Pubs/Catalogs/Ugrad/Current/ascourses.html#as1001">AS 1001</A> A01</TD> <TD>FOUNDATIONS OF US AIR FORCE I</TD> <TD> 1/9</TD> <TD>Lec</TD> <TD>--W--</TD> <TD>2:00-2:50</TD> <TD>HL202</TD> <TD><A HREF="http://www.wpi.edu/Pubs/Faculty/brk.html">Kaanta, Bryan R.</A></TD> * */ preg_match_all("/#.+?\"\\>([A-Z]+)\\s(\\d+)\\<\\/A\\>(.+?)\\<\\/TD\\>\n\\<TD\\>(.+?)\\<\\/TD\\>\n.+\n.+\n.+\n.+\n.+\n\\<TD\\>(.*)\\<\\/TD/", $result, $matches2, PREG_SET_ORDER); print_r($matches2); foreach ($matches2 as $n) { $section = SectionQuery::create()->filterBySchool($school)->filterByNum($n[3])->useCourseQuery()->filterByNum($n[2])->useDeptQuery()->filterByAbbr($n[1])->endUse()->endUse()->findOne(); if ($section) { $section->setName(formatCourseName($n[4])); if (preg_match("/\\>(.+),/", $n[5], $mat)) { $section->setProfessor($mat[1]); } $section->save(); } } } //"<A HREF="/pls/prod/hwwkrnbw.P_DisplayDept?sel_term=201101&sel_ptrm=A&sel_dept=AS&sel_desc=Aerospace+Studies++(AFROTC)&sel_level=01&sel_campus=x">Aerospace Studies (AFROTC)</A>
$term = '201130'; require_once __DIR__ . '/../functions.php'; $school = SchoolQuery::create()->filterBySlug('northeastern')->findOne(); // update departments $depts = curl_post("https://bnr8ssbp.neu.edu/udcprod8/bwckctlg.p_disp_cat_term_date", array('call_proc_in' => 'bwckctlg.p_disp_dyn_ctlg', 'cat_term_in' => $term)); preg_match("/sel_dept.+?\\/SELECT/s", $depts, $matches); preg_match_all("/VALUE\\=\"(.+?)\"\\>(.+?)\\</s", $matches[0], $matches, PREG_SET_ORDER); foreach ($matches as $m) { $dept = DeptQuery::create()->filterBySchool($school)->filterByAbbr($m[1])->findOne(); if ($dept) { $dept->setName($m[2])->save(); } } $courses = CourseQuery::create()->filterBySchool($school)->find(); foreach ($courses as $c) { $result = curl_get("https://bnr8ssbp.neu.edu/udcprod8/bwckctlg.p_disp_course_detail?" . "cat_term_in={$term}&subj_code_in=" . $c->getDept()->getAbbr() . "&crse_numb_in=" . $c->getNum()); if (preg_match('/' . $c->getDept()->getAbbr() . '\\s' . $c->getNum() . '\\s\\-\\s(.+?)\\</', $result, $matches)) { echo $c->getDept()->getAbbr() . $c->getNum() . "\n"; $c->setName(htmlspecialchars_decode($matches[1]))->save(); } $url = "https://bnr8ssbp.neu.edu/udcprod8/bwckctlg.p_disp_listcrse?term_in={$term}&subj_in=" . $c->getDept()->getAbbr() . "&crse_in=" . $c->getNum() . "&schd_in="; $sections = curl_get($url); if (preg_match_all("/(\\d{5})\\s\\-\\s.+?Instructors\\:\\s\\<\\/SPAN\\>(.+?)(?:\\<|\\()/s", $sections, $matches, PREG_SET_ORDER)) { foreach ($matches as $m) { $section = SectionQuery::create()->filterByCourse($c)->filterByNum($m[1])->findOne(); if ($section) { $section->setProfessor(trim($m[2]))->save(); } } } }
// we should already be spidered down to the department level for all schools $dept = DeptQuery::create()->filterBySchool($school)->where('Dept.SpideredAt < ?', time() - 60)->orWhere('Dept.SpideredAt IS NULL')->withColumn('RAND()', 'rand')->orderBy('rand')->findOne(); if (!$dept) { echo "WTF\n"; break; } echo $dept->getAbbr(); Spiderer::spider($dept, true, 0); $course = CourseQuery::create()->filterByDept($dept)->where('Course.SpideredAt < ?', time() - 60)->orWhere('Course.SpideredAt IS NULL')->withColumn('RAND()', 'rand')->orderBy('rand')->findOne(); if (!$course) { echo "WTF\n"; break; } echo $course->getNum(); Spiderer::spider($course, true, 0); $section = SectionQuery::create()->filterByCourse($course)->where('Section.SpideredAt < ?', time() - 60)->orWhere('Section.SpideredAt IS NULL')->withColumn('RAND()', 'rand')->orderBy('rand')->findOne(); if (!$section) { echo "WTF\n"; break; } echo $section->getNum(); $sectionSpiderer->spider(array($section), 0); $shis = SectionHasItemQuery::create()->filterBySection($section)->joinWith('SectionHasItem.Item'); $goodCount = $shis->keepQuery()->where('Item.Isbn IS NOT NULL')->where('Item.Isbn != ?', '')->count(); $itemsCount = $shis->count(); } if ($goodCount) { echo $school->getSlug() . ": found a suitable item\n"; $goodSchools[] = $school; } else { if ($itemsCount) {
<?php /** * sections SCHOOL [--force] * * Spider all the sections for SCHOOL. If --force, spider even sections * that have been spidered recently. */ if (!isset($argv[1])) { echo "You must provide a school."; exit; } $s = SectionQuery::create()->filterByRequiresBooks(1)->orderBySpideredAt('ASC')->filterBySchoolSlug($argv[1])->withColumn('RAND()', 'rand')->orderBy('rand')->find(); $sections = array(); foreach ($s as $section) { if ($section->needsSpidering() || in_array('--force', $argv)) { if (!$section->getSpideredAt()) { //continue; } $sections[] = $section; } } if ($sections) { $sectionsPerRequest = 5; $bookstore = $sections[0]->getBookstoreType(); $bookstore = new $bookstore(); $force = in_array('--force', $argv); for ($i = 0; $i < count($sections);) { $rand = rand(4, $sectionsPerRequest); echo "Spidering: "; $sects = array_slice($sections, $i, $rand);