/** * @param array $isbns array of potentially invalid 10 or 13-digit ISBNs * @param array $slugs array of potentially invalid Section slugs */ public function __construct($isbns, $sectionSlugs = array(), $schoolSlug = '', $termSlug = '', $campusSlug = '') { global $tag, $school, $vendors, $state, $defaultTag; $this->isbns = array_map('Isbn::to13', $isbns); $this->sectionSlugs = $sectionSlugs; $this->schoolSlug = $schoolSlug; $this->campusSlug = $campusSlug; $this->termSlug = $termSlug; $school = SchoolQuery::create()->findOneBySlug($this->schoolSlug); // 1 query // process school if ($school) { $tag = $school->getAmazonTag(); // uses session tag if set $this->bookstore = $school->getBookstoreType(); $vendors[array_search('Bookstore', $vendors)] = $this->bookstore; $state = $school->getState(); } else { if ($schoolSlug) { throw new GetchabooksError("Unknown school slug: {$schoolSlug}"); } else { $this->sectionSlugs = null; $tag = isset($_SESSION['tag']) ? $_SESSION['tag'] : $defaultTag; unset($vendors[array_search('Bookstore', $vendors)]); $state = null; } } if ($this->schoolSlug) { $this->spiderSections(); } $this->fetchData(); $this->makePackages(); }
public function campuses($school) { $school = SchoolQuery::create()->findOneBySlug($school); if ($school) { $school->spider(2); echo json_encode($school->getCampusSelect()); } else { throw new AjaxError("Expected item doesn't exist."); } }
/** * Sets the slug, checking for duplicates and appending a number to make it unique if they exist. */ public function setSlug($slug, $i = 0) { $preExisting = SchoolQuery::create(); if ($this->getId()) { $preExisting->where('School.Id != ?', $this->getId()); } $preExisting->filterBySlug($i ? $slug . $i : $slug); if ($preExisting->findOne()) { $this->setSlug($slug, $i + 1); } else { parent::setSlug($i ? $slug . $i : $slug)->save(); } return $this; }
* a depth of 2 (department-aware). * * If SCHOOL is the exact name of a bookstore type, then the department-aware * spidering will be limited to schools of that bookstore type. * * If --disabled, even disabled schools will be spidered. */ $bookstore = @file_exists(BASE_DIR . "/models/Vendors/Bookstores/{$argv[1]}.php"); if (isset($argv[1]) && !$bookstore) { $school = SchoolQuery::create()->filterBySlug($argv[1])->findOne(); if ($school) { $school->spider(4); $school->setTouched(1)->setEnabled(1)->save(); $school->updateCourseInfo(); } else { echo "Unknown school: {$argv[1]}\n"; } } else { $schools = SchoolQuery::create(); if ($bookstore) { $schools->filterByBookstoreType($argv[1]); } if (!in_array('--disabled', $argv)) { $schools->filterByEnabled(1); } foreach ($schools->find() as $school) { $school->setTouched(0)->save(); $school->spider(2); $school->setTouched(1)->save(); } }
/** * 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(SchoolPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = SchoolQuery::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; } }
<?php /** * dump [--reset] * * Dump the current state of the schools table to XML. */ $reset = in_array('--reset', $argv); $xmlDir = BASE_DIR . '/config'; $attributes = array('Name', 'ShortName', 'Slug', 'State', 'Zip', 'LocalTax', 'AmazonTag', 'Subdomain', 'BId'); $xmls = array(); $schools = SchoolQuery::create()->orderBy('Slug')->find(); foreach ($schools as $school) { $bookstore = $school->getBookstoreType(); $xml = ""; if (!$school->getEnabled()) { $xml .= "<!--"; } $xml .= "\t<school>\n"; foreach ($attributes as $a) { if ($a == 'AmazonTag' && $school->getAmazonTag() == 'txtbks-20') { continue; } $xml .= "\t\t<{$a}>" . htmlentities(call_user_func(array($school, "get{$a}"))) . "</{$a}>\n"; } $xml .= "\t</school>\n"; if (!$school->getEnabled()) { $xml .= "-->"; } if (!isset($xmls[$bookstore])) { $xmls[$bookstore] = "<schools>\n";
<?php /** * courseinfo SCHOOL * * CourseInfo updating happens automatically when a school is done fully * spidering, but sometimes you might want to do it on its own. */ if (!isset($argv[1])) { die("No school provided.\n"); } $school = SchoolQuery::create()->filterBySlug($argv[1])->findOne(); $school->updateCourseInfo();
<?php require_once "../functions.php"; $departments = array("AR" => "Art History/Architecture/Essentials of Art", "AS" => "Air Science", "BCB" => "Bioinformatics and Computational Biology", "BB" => "Biology", "CHE" => "Chemical Engineering", "CH" => "Chemistry", "CE" => "Civil Engineering", "CS" => "Computer Science", "ECE" => "Electrical and Computer Engineering", "EN" => "English", "GN" => "German", "HI" => "History", "HU" => "Humanities & Arts", "MU" => "Music", "PY" => "Philosophy", "RE" => "Religion", "WR" => "Writing", "SP" => "Spanish", "BUS" => "Business", "CPE" => "Corporate & Professional Education", "ECON" => "Economics", "ENV" => "Environmental Studies", "ES" => "Engineering Science", "ETR" => "Entrepreneurship", "EX" => "Exchange Program", "FIN" => "Finance", "FP" => "Fire Protection Engineering", "FY" => "First Year", "GE" => "Geology", "GOV" => "Political Science, Government and Law", "IMGD" => "Interactive Media and Game Development", "ISE" => "International Students (English)", "ID" => "Interdisciplinary", "MFE" => "Manufacturing Engineering", "MIS" => "Management Information Systems", "MKT" => "Marketing", "MTE" => "Material Science & Engineering", "MA" => "Mathematical Sciences", "ME" => "Mechanical Engineering", "MG" => "Management Communication", "ML" => "Military Leadership", "MME" => "Mathematics for Educators", "OBC" => "Organizational Behavior and Change", "OIE" => "Operations and Industrial Engineering", "PE" => "Physical Education", "PH" => "Physics", "RBE" => "Robotics Engineering", "SS" => "Social Science", "PSY" => "Psychology", "RH" => "Rhetoric", "SD" => "System Dynamics", "SOC" => "Sociology", "STS" => "Society & Technology Studies", "SP" => "Spanish", "SYS" => "Systems Engineering"); $school = SchoolQuery::create()->filterByBnSubdomain('wpi')->findOne(); // update departments $url = "http://rewww.wpi.edu/academics/catalogs/ugrad/programdesc.html"; $url2 = "http://rewww.wpi.edu/academics/catalogs/grad/academ44.html"; $result = curl_get($url) . curl_get($url2); preg_match_all("/title\\=\"(.+?)\" href\\=\".+\\/(.+)(dept)?\\.html\"/", $result, $matches, PREG_SET_ORDER); foreach ($matches as $m) { $abbr = str_replace("dept", "", $m[2]); $dept = DeptQuery::create()->filterBySchool($school)->filterByAbbr($abbr)->findOne(); if ($dept) { $dept->setName(trim($m[1]))->save(); } } foreach ($departments as $abbr => $name) { $dept = DeptQuery::create()->filterBySchool($school)->filterByAbbr($abbr)->findOne(); if ($dept) { $dept->setName($name)->save(); } } // update courses $term = '201101'; $url = "https://banner-as1.admin.wpi.edu/pls/prod/hwwkrnbw.P_GetDepts?sel_term={$term}&sel_ptrm=S&sel_level=01&sel_campus=x"; $result = curl_get($url) . curl_get(str_replace("level=01", "level=05", $url)); preg_match_all("/(\\/pls.+dept\\=([A-Z]+).+x)\"\\>(.+?)\\<\\/A\\>/", $result, $matches, PREG_SET_ORDER); echo "<pre>"; print_r($matches); foreach ($matches as $m) {
<?php $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(); } }
<?php require_once __DIR__ . "/../functions.php"; $departments = array("ACC" => "Accounting", "AHF" => "Arts & Humanities Foundation", "AMS" => "American Studies", "ART" => "Art", "ASM" => "Advanced Strategic Management", "BPR" => "Business Practicum Program", "BRC" => "BRIC", "CGE" => "Cross-Registration Courses", "CHN" => "Chinese", "COM" => "Communications", "CVA" => "Culture and Values", "CXD" => "Offshore Course", "ECN" => "Economics", "ENG" => "English", "EPS" => "Entrepreneurship", "EXC" => "Babson Study Abroad", "FIN" => "Finance", "FLM" => "Film", "FME" => "Foundation of Management & Entrepreneurship (FME)", "FRN" => "French", "FYS" => "First-Year Seminar", "GDR" => "Gender Studies", "HIS" => "History", "HSF" => "History & Society Foundation", "HSS" => "History & Society", "IMH" => "Honors Seminar", "IND" => "Independent Research", "JPN" => "Japanese", "LAW" => "Law", "LIB" => "Liberal Arts", "LIT" => "Literature", "LVA" => "Literature & Visual Arts", "MBA" => "MBA", "MCE" => "Managing in a Competitive Environment (MCE)", "MDS" => "Media Studies", "MFE" => "Management Consulting Field Experience (MCFE)", "MIS" => "Management Information Systems", "MKT" => "Marketing", "MOB" => "Management", "OEM" => "Organizing for Effective Management (OEM)", "OLIN" => "Olin College of Engineering Cross Registration", "OPS" => "Operations", "PHL" => "Philosophy", "PHO" => "Photography", "POL" => "Politics", "PRF" => "Performing Arts", "PSA" => "Petition Study Abroad", "PSY" => "Psychology", "QTM" => "Quantitative Methods", "RHT" => "Rhetoric", "SCN" => "Science", "SPN" => "Spanish", "TAX" => "Taxes", "VSA" => "Visual Arts", "WRT" => "Writing"); $school = SchoolQuery::create()->findOneBySlug('babson'); // update departments $depts = DeptQuery::create()->filterBySchool($school)->find(); foreach ($depts as $d) { if (isset($departments[$d->getAbbr()])) { $d->setName($departments[$d->getAbbr()])->save(); } } // update courses $term = "Spring+2011"; $url1 = "http://fusionmx.babson.edu/CourseListing/index.cfm?fuseaction=CourseListing.DisplayCourseListing&blnShowHeader=false&program=Graduate&semester={$term}&sort_by=course_number&btnSubmit=Display+Courses"; $url2 = "http://fusionmx.babson.edu/CourseListing/index.cfm?fuseaction=CourseListing.DisplayCourseListing&blnShowHeader=false&program=Undergraduate&semester={$term}&sort_by=course_number&btnSubmit=Display+Courses"; $result = curl_get($url2) . curl_get($url1); preg_match_all("/85\"\\>([A-Z]+)(\\d+)\\-([A-Z\\d]+)\\<\\/td\\>.+?400\\);\"\\>(.+?)\\<\\/a.+?nowrap\"\\>(.+?),.+?\\<\\/span/s", $result, $matches, PREG_SET_ORDER); foreach ($matches as $m) { unset($m[0]); print_r($m); $dept = DeptQuery::create()->filterBySchool($school)->filterByAbbr($m[1])->findOne(); if (!$dept) { continue; } $course = CourseQuery::create()->filterByDept($dept)->filterByNum(ltrim($m[2], '0'))->findOne(); if (!$course) { continue; } $name = preg_replace("/\\(.+\\)\$/", "", $m[4]); $course->setName(formatCourseName($name))->save();
<?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) {
/** * Finds the related School objects and keep them for later * * @param PropelPDO $con A connection object */ protected function findRelatedSchools($con) { $criteria = clone $this; if ($this->useAliasInSQL) { $alias = $this->getModelAlias(); $criteria->removeAlias($alias); } else { $alias = ''; } $this->schools = SchoolQuery::create()->joinCampus($alias)->mergeWith($criteria)->find($con); }
<?php $bc = SchoolQuery::create()->filterBySlug('bc')->findOne(); $campuses = $bc->getCampuss(); $currentTerm = $campuses[0]->getCurrentTerm(); $depts = array('01' => array('BI' => 'Biology', 'BK' => 'African and African Diaspora Studies', 'CH' => 'Chemistry', 'CL' => 'Classical Studies', 'CO' => 'Communication', 'CS' => 'Computer Science', 'CT' => 'Theater', 'EC' => 'Economics', 'EN' => 'English', 'FA' => 'Fine Arts/Art History', 'FM' => 'Film Studies', 'FS' => 'Fine Arts/Studio Art', 'GE' => array('Earth and Environmental Sciences', 'Earth and Environmental Sciences'), 'GM' => 'Germanic Studies', 'HP' => 'Honors Program', 'HS' => 'History', 'IC' => 'Islamic Civilization and Societies', 'IN' => 'International Studies', 'MT' => 'Mathematics', 'MU' => 'Music', 'PH' => 'Physics', 'PL' => 'Philosophy', 'PO' => 'Political Science', 'PS' => 'Psychology', 'RL' => 'Romance Languages/Literatures', 'SC' => 'Sociology', 'SL' => 'Slavic and Eastern Languages', 'TH' => 'Theology', 'UN' => 'University Courses and Capstone'), '04' => array('LL' => 'Law'), '05' => array('AD' => 'Administrative Studies', 'BA' => array('Advancing Studies/Accounting', 'adv studies/accounting'), 'BF' => array('Advancing Studies/Finance', 'adv studies/finance'), 'BI' => 'Biology', 'BL' => array('Advancing Studies/Law', 'adv studies/law'), 'BM' => array('Advancing Studies Management/Marketing', 'ad studies mgmnt/marketing'), 'CO' => 'Communication', 'EC' => 'Economics', 'ED' => 'Education', 'EN' => 'English', 'FA' => 'Fine Arts/Art History', 'GM' => 'Germanic Studies', 'HS' => 'History', 'LA' => array('Advancing Studies/Law', 'adv studies/law'), 'MT' => 'Mathematics', 'PL' => 'Philosophy', 'PO' => 'Political Science', 'PS' => 'Psychology', 'RL' => 'Romance Languages/Literatures', 'SC' => 'Sociology', 'TH' => 'Theology'), '06' => array('SW' => 'Social Work'), '07' => array('MA' => 'Accounting', 'MB' => array('Organizational Studies/Human Resource Management', 'organizatnl std/human res mgmt'), 'MD' => array('Operations, Information & Strategic Management', 'operations,information & strategic mgmt'), 'MF' => 'Finance', 'MH' => array('Undergrad Management Honors/Ethics', 'undergrad mgmt honors/ethics'), 'MI' => 'Information Systems', 'MJ' => 'Business Law', 'MK' => 'Marketing', 'MM' => array('Graduate Management Practice/International', 'grad mgmt practice/international')), '08' => array('NU' => 'Nursing'), '09' => array('ED' => 'Education', 'PY' => 'Education/Psychology'), '18' => array('TM' => 'Theology and Ministry')); foreach ($depts as $schoolNum => $ds) { foreach ($ds as $abbr => $name) { if (is_array($name)) { $formatted = $name[0]; $lookup = $name[1]; } else { $formatted = $name; $lookup = strtolower($name); } $data = array('BUTNS' => '', 'DAYS' => 'A', 'DEPT' => "{$abbr}={$lookup}", 'DEPT00' => "", 'DEPT01' => "", 'DEPT05' => $schoolNum == '05' ? "{$abbr}={$lookup}" : "", 'DEPT07' => "", 'DEPT09' => "", 'EDIT.DEPT.ENTERED' => 'Select a department', 'EDIT.TERM.ENTERED' => 'Select a term', 'ETIME' => 'ALL', 'FORMNAME' => 'course.schedule', 'LEVEL' => 'A', 'PROF' => '', 'SCHOOL' => $schoolNum, 'STATUS' => 'A', 'STIME' => 'ALL', 'TERM' => '2012S', 'TITLE' => ''); $result = Curl::post("https://agora.bc.edu/cgi-bin/uiscgi?wwmr", $data); // with course popup hyperlink $regex1 = "/\\<td\\>[^>]+?\\>([A-Z]{2})(.+?)(..)\\<.+?\\<td\\>.+?\\<td\\>.+?\\<td\\>.+?\\<td\\>(.+?)\\<\\/td\\>.+?\\<td\\>.+?\\<td\\>.+?\\<td\\>[^>]+?\\>(.+?)\\</s"; // without course popup hyperlink $regex2 = "/\\<td\\>\\s*([A-Z]{2})([A-Z0-9]+?)([A-Z0-9]{2})\\<\\/td.+?\\<td\\>.+?\\<td\\>.+?\\<td\\>.+?\\<td\\>(.+?)\\<\\/td\\>.+?\\<td\\>.+?\\<td\\>.+?\\<td\\>[^>]+?\\>(.+?)\\</s"; if (!preg_match_all($regex1, $result, $matches, PREG_SET_ORDER)) { 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) {
/** * Get the associated School object * * @param PropelPDO Optional Connection object. * @return School The associated School object. * @throws PropelException */ public function getSchool(PropelPDO $con = null) { if ($this->aSchool === null && $this->school_id !== null) { $this->aSchool = SchoolQuery::create()->findPk($this->school_id, $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->aSchool->addCampuss($this); */ } return $this->aSchool; }
public static function addSchools() { $class = get_called_class(); decho("Adding schools for {$class}"); foreach (static::getSchools() as $data) { print_r($data); $school = SchoolQuery::create()->filterByBookstoreType($class)->filterBySubdomain($data['Subdomain'])->findOne(); if (!$school) { $school = new School(); $school->setBookstoreType($class)->setSubdomain($data['Subdomain']); } $school->setSlug($data['Slug'])->setName($school->getName() ?: $data['Name'])->setShortName($school->getShortName(true) ?: (isset($data['ShortName']) ? $data['ShortName'] : School::guessShortName($data['Name'], $data['Slug'])))->setTouched(1)->save(); } }
<?php require_once __DIR__ . '/../functions.php'; $term = '1103'; $school = SchoolQuery::create()->filterBySlug('temple')->findOne(); $school->setDeptsToIgnore("CANCL TEXT")->save(); // temporarily, let's reset all the courses and sections' names and professors //CourseQuery::create()->filterBySchool($school)->update(array('Name' => null)); //SectionQuery::create()->filterBySchool($school)->update(array('Professor' => null)); /** * key is the department abbreviation as it appears on bncollege. Value is the name as it appears * on the temple course catalog. Value can be an array if the second value should be substituted * for the first value in our database. But, 'And' => 'and' and 'Of' => 'of' happen automatically. */ $deptNames = array('ACCT' => 'Accounting', 'ACT SCI' => 'Actuarial Science', 'ADVERTISIN' => 'Advertising', 'AFR-AMER S' => 'African American Studies', 'AMER ST' => 'American Studies', 'ANTHRO' => 'Anthropology', 'AOD' => 'Adult And Organizational Development', 'ARABIC' => 'Arabic', 'ARCH' => 'Architecture', 'ART' => 'Art', 'ART ED' => 'Art Education', 'ART H' => 'Art History', 'ASIA ST' => 'Asian Studies', 'BIOLOGY' => 'Biology', 'BTMM' => 'Broadcast Telecom Mass Media', 'BUS' => 'Business', 'BUS ADM' => 'Business Administration', 'C+IN SC' => 'Computer + Information Science', 'C+R PLN' => 'Community & Regional Planning', 'CCET' => 'Civil + Construction Eng Tech', 'CHEM' => 'Chemistry', 'CHINESE' => 'Chinese', 'CIVIL ENG' => 'Civil Engineering', 'CN PSY' => 'Counseling Psychology', 'COMM SCI' => 'Comm Sciences + Disorders', 'COMM+TH' => 'Communications And Theater', 'CR LANG' => 'Critical Languages Center', 'CRIM JUSTI' => 'Criminal Justice', 'DANCE' => 'Dance', 'DISABILITY' => 'Disability Studies', 'EARTH/ENVI' => 'Earth & Environmental Science', 'ECH ED' => 'Early Childhood Education', 'ECON' => 'Economics', 'ED ADM' => 'Educational Administration', 'ED PSY' => 'Educational Psychology', 'EDUCATION' => 'Education', 'ELECTR ENG' => 'Electrical Engineering', 'ELEM ED' => 'Elementary Education', 'EN ED-E' => 'English Education, Elementary', 'EN ED-S' => 'English Education, Sec Ed', 'ENGLISH' => 'English', 'ENGRG' => 'Engineering', 'ENVIRO STD' => 'Environmental Studies', 'ENVT' => '', 'ET' => 'Engineering Technology', 'FINANCE' => 'Finance', 'FL ED-S' => 'Foreign Lang Ed, Secondary Ed', 'FMA' => 'Film And Media Arts', 'FOUNDATION' => 'Foundations', 'FRENCH' => 'French', 'GEN/STRA M' => '', 'GEOG' => 'Geography And Urban Studies', 'GERMAN' => 'German', 'GK+ROM CL' => 'Greek And Roman Classics', 'GREEK' => 'Greek', 'GREEK,ANC' => 'Greek Ancient', 'GREEK,MODE' => 'Greek, Modern', 'HEBREW' => 'Hebrew', 'HINDI' => 'Hindi', 'HISTORY' => 'History', 'HLTH INF M' => 'Health Information Management', 'HLTH RL PR' => 'Health Related Professions', 'HLTHCARE M' => 'Healthcare Management', 'HORT' => 'Horticulture', 'HUM RES MG' => 'Human Resource Management', 'IBA' => 'International Business Admin', 'IELP' => '', 'IH' => 'Intellectual Heritage', 'ITALIAN' => 'Italian', 'JAPANESE' => 'Japanese', 'JEWISH ST' => 'Jewish Studies', 'JOURNALISM' => 'Journalism', 'KINESIOLOG' => 'Kinesiology', 'KOREAN' => 'Korean', 'LANDSC' => 'Landscape Architecture', 'LATIN' => 'Latin', 'LATIN AM S' => 'Latin American Studies', 'LAW SBM' => 'Law S.B.M.', 'LESBIAN GB' => 'Lesbian Gay Bi & Tg St', 'LIB ARTS' => 'Liberal Arts', 'M ED-E' => 'Math Education, Elementary Ed', 'M ED-S' => 'Math Education, Secondary Ed', 'M L A' => 'Master Of Liberal Arts', 'MASSMEDIAC' => 'Mass Media And Communication', 'MATH' => 'Mathematics', 'MECH ENG' => 'Mechanical Engineering', 'MESSIAH' => '', 'MET' => 'Mechanical Engineering Technol', 'MGT INFO S' => 'Management Information Systems', 'MIL SCI' => 'Military Science', 'MKTG' => 'Marketing', 'MSOM' => 'Management Science/Oper Mgt', 'MUS ED' => 'Music Education', 'MUS ST' => 'Music Studies', 'MUSIC' => 'Music', 'NEUROSCI C' => 'Neuroscience - Cla', 'NURSING' => 'Nursing', 'OC THER' => 'Occupational Therapy', 'PHETE' => 'Phete', 'PHILOS' => 'Philosophy', 'PHYSICS' => 'Physics', 'POL SCI' => 'Political Science', 'PSYCH' => 'Psychology', 'PUBLIC HLT' => 'Public Health', 'REL' => 'Religion', 'RL EST' => 'Real Estate', 'RSK MGT +' => 'Risk Management And Insurance', 'RUSSIAN' => 'Russian', 'SC ED-E' => 'Science Education, Elementary', 'SC ED-S' => 'Science Education, Secondary E', 'SCH PSY' => 'School Psychology', 'SEC ED' => 'Secondary Education', 'SOC' => 'Sociology', 'SOC WRK GR' => 'Social Work Graduate', 'SOCWRK UND' => 'Social Work Undergrad', 'SPANISH' => 'Spanish', 'SPEC ED' => 'Special Education', 'SPEC ORD' => '', 'SS ED-E' => 'Social Studies Education, Elem', 'SS ED-S' => 'Social Studies Ed, Sec Ed', 'STAT' => 'Statistics', 'STRAT COMM' => 'Strategic Communications', 'STRATGIC M' => 'Strategic Management', 'TESOL' => 'Teach Engl Speakr Of Othr Lang', 'THEATER' => 'Theater', 'THERAP REC' => 'Therapeutic Recreation', 'TOUR HOS M' => 'Tourism & Hospitality Mgmt', 'UNIV SEMI' => 'Univ Seminar', 'URB ED' => 'Urban Education', 'VIETNAMESE' => 'Vietnamese', 'WOM STD' => 'Womens Studies'); function getDeptName($abbr, $fixed = false) { global $deptNames; if ($deptNames[$abbr]) { if (is_array($deptNames[$abbr])) { return $fixed && isset($deptNames[$abbr][1]) ? $deptNames[$abbr][1] : str_pad($deptNames[$abbr][0], 31); } else { return str_pad($deptNames[$abbr], 31); } } else { return false; } } // update departments $depts = DeptQuery::create()->filterBySchool($school)->find(); foreach ($depts as $dept) {
public function savePage() { global $app, $siteName, $siteUrl; $args = func_get_args(); $in = array(); if (count($args) == 5) { list($email, $school, $campus, $term, $ids) = $args; } else { list($email, $school, $term, $ids) = $args; $campus = null; } if (!$this->validate($email)) { echo "false"; return; } $in['school'] = $school; $in['campus'] = $campus; $in['term'] = $term; $in['ids'] = htmlspecialchars($ids); 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'; $numItems = count(explode(SECTION_DELIMITER, $ids)); $numWithRegularNoun = function ($num, $noun) { return ($num > 1 ? cardinal($num) . ' ' : '') . $noun . ($num > 1 ? 's' : ''); }; if ($school == 'isbn') { $yourX = "your " . $numWithRegularNoun($numItems, 'book'); } else { if ($school = SchoolQuery::create()->findOneBySlug($school)) { $schoolName = $school->getName(); $yourX = "all your books for your " . $numWithRegularNoun($numItems, 'course') . " at {$schoolName}"; } else { echo "false"; return; } } $date = date('l, F j'); $subject = "Your Textbooks at {$siteUrl}"; $body = <<<END Hey there, Here's a link to {$yourX}: {$url} Use that link at any time to come back to {$siteName} and find the lowest prices for your textbooks. Have a great semester! We'll see you soon. -- You're receiving this email because on {$date}, someone visited {$siteUrl} and requested an email reminder with a link to their textbooks. 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($email, $subject, $body); echo "true"; } catch (Exception $e) { echo "false"; throw $e; } }
<?php /** * json * * Regenerate schools.json */ $schools = SchoolQuery::create()->filterByEnabled(1)->orderBy('School.Name', 'asc')->find(); $rows = array(); foreach ($schools as $school) { $rows[] = array('name' => $school->getName(), 'nickname' => $school->getShortName(), 'slug' => $school->getSlug()); } $json = json_encode($rows); file_put_contents(BASE_DIR . '/config/schools.json', $json); $gbCache->set('schooljson', $json);
if (libxml_get_errors()) { echo "Errors in {$abbr}-schools.xml, skipping.\n"; continue; } foreach ($schools->school as $school) { if ($obj = SchoolQuery::create()->filterBySlug($school->Slug)->findOne()) { if ($bookstoreType != $obj->getBookstoreType()) { echo "Tried to add a school for a slug that already exists, skipping: {$school->Slug}\n"; continue; } else { $obj->setTouched(true)->save(); } } $query = SchoolQuery::create()->filterByBookstoreType($bookstoreType); $obj = $query->filterBySlug($school->Slug)->findOne(); if (!$obj) { $obj = new School(); $obj->setSlug($school->Slug)->setBookstoreType($bookstoreType); echo "Adding new school: {$school->Slug}\n"; } $obj->setName(html_entity_decode($school->Name))->setShortName(html_entity_decode($school->ShortName))->setSlug($school->Slug)->setState($school->State)->setZip($school->Zip)->setLocalTax($school->LocalTax)->setAmazonTag($school->AmazonTag ?: 'txtbks-20')->setSubdomain($school->Subdomain)->setBId($school->BId)->setTouched(1)->setEnabled(1)->save(); } } $untouchedSchools = SchoolQuery::create()->filterByTouched(false)->find(); foreach ($untouchedSchools as $school) { if ($school->getEnabled()) { echo "Disabling " . $school->getSlug() . "\n"; $school->setEnabled(0)->save(); } } require_once __DIR__ . '/json.php';
$goodSchools[] = $school; } else { if ($shis->keepQuery()->count() >= 10) { echo "{$slug}: didn't find a suitable item, adding to bad schools\n"; $badSchools[] = $school; } else { $unsureSchools[] = $school; } } } return array($goodSchools, $badSchools, $unsureSchools); } // BEGIN MAIN SCRIPT $debug = true; // identify schools which already have at least one section spidered with a book with an isbn $schools = SchoolQuery::create()->orderBy('School.Slug', 'asc')->find(); list($goodSchools, $badSchools, $unsureSchools) = doMinimalTest($schools); // randomly spider bad schools until we've found a section with an isbn or are pretty sure that the school doesn't list isbns $newUnsureSchools = array(); foreach ($unsureSchools as $i => $school) { if (in_array($school->getSlug(), array('columbia'))) { $badSchools[] = $school; continue; } if (in_array($school->getSlug(), array('jwu', 'ohiostate', 'puc', 'spu'))) { $badSchools[] = $school; continue; } deleteCookieFile(); echo $school->getSlug(); $sectionClass = str_replace('School', 'Section', get_class($school));
<?php require_once __DIR__ . "/../functions.php"; $term = "spring2011"; $departmentFixes = array("Political Science (formerly GOVT)" => "Political Science"); $school = SchoolQuery::create()->filterBySlug('clarku')->findOne(); // update departments $result = file_get_contents("http://www.clarku.edu/offices/src/courses/courselist{$term}.cfm"); preg_match_all("/anchor\"\\>([A-Z]+)\\s-\\s(.+)\\<\\/a/", $result, $matches, PREG_SET_ORDER); foreach ($matches as $m) { $dept = DeptQuery::create()->filterBySchool($school)->filterByAbbr(trim($m[1]))->findOne(); if ($dept) { $m[2] = trim($m[2]); $name = in_array($m[2], array_keys($departmentFixes)) ? $departmentFixes[$m[2]] : $m[2]; $dept->setName($name)->save(); } } // update courses $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) {