コード例 #1
0
 private function extractCourseInfo(\DOMDocument $dom, $data)
 {
     $key = $dom->getElementsByTagName('h3')->item(0);
     preg_match('~\\s+([A-Z]+\\s+\\d+[A-Z]*)\\.\\s+([^\\n]+)\\s+\\((\\d+).*\\)\\.\\s+~', $key->textContent, $matches);
     $course_id = $data['subject'] . $data['level'];
     $course = Course::firstOrNew(['id' => $course_id]);
     $course_info = ['id' => $course_id, 'level' => $data['level'], 'title' => trim($matches[2]), 'description' => trim($key->nextSibling->wholeText), 'subject_id' => Subject::find($data['subject'])->id];
     if (!is_null($dom->getElementById('ctl00_ContentPlaceHolder1_lblCoursePrereqs'))) {
         $course_info['prereqs'] = trim($dom->getElementById('ctl00_ContentPlaceHolder1_lblCoursePrereqs')->nextSibling->wholeText);
     }
     foreach ($course_info as $key => $value) {
         $course->{$key} = $value;
     }
     $course->save();
     return $course_info;
 }
コード例 #2
0
 public function scrape($job, $data)
 {
     $url = sprintf(self::CATALOG_URL . self::QUERY_PARAMS, $data['campus'] ?: 'corvallis', $data['term'] ?: '');
     $contents = file_get_contents($url);
     Model::unguard();
     array_map(function ($subj) {
         try {
             if (is_null(Subject::find($subj)->first())) {
                 $subj = Subject::create($subj);
                 print_r($subj->toArray());
             }
             \Queue::push('Courses\\Jobs\\Scraper\\ScrapeSubject', ['subject' => $subj['id']]);
         } catch (Illuminate\Database\QueryException $e) {
         }
     }, $this->getSubjects($contents));
     $job->delete();
 }
コード例 #3
0
ファイル: Subject.php プロジェクト: beavers-io/legacy-api
 public static function bySubjcode($subjcode)
 {
     return Subject::whereSubjcode($subjcode)->first();
 }
コード例 #4
0
 public function run()
 {
     foreach (Subject::all() as $subj) {
         $this->createCourses($subj);
     }
 }