/**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $client = new \GuzzleHttp\Client(['cookies' => true, 'timeout' => 20.0, 'connect_timeout' => 20.0, 'verify' => false, 'headers' => ['User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2398.0 Safari/537.36', 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Encoding' => 'gzip, deflate, sdch', 'Accept-Language' => 'en-US,en;q=0.8', 'Dnt' => '1', 'Pragma' => 'no-cache', 'Cache-Control' => 'no-cache', 'Host' => 'ais-cs.ucsc.edu', 'Origin' => 'https://ais-cs.ucsc.edu', 'Connection' => 'keep-alive', 'DNT' => 1]]);
     $counter = 0;
     do {
         $decrypted = Crypt::decrypt($this->user->gold_password);
         $login = $client->request('POST', 'https://ais-cs.ucsc.edu/psc/csprd/EMPLOYEE/PSFT_CSPRD/c/SA_LEARNER_SERVICES.SSR_SSENRL_CART.GBL?cmd=login&languageCd=ENG', ['form_params' => ['timezoneOffset' => 480, 'Submit' => 'Sign In', 'userid' => $this->user->cruz_id, 'pwd' => $decrypted]]);
         $html = new \Htmldom();
         $html->load($login->getBody());
         $classes = [];
         $rows = $html->find('table.PSLEVEL2GRIDWBO a.PSHYPERLINK');
         foreach ($rows as $row) {
             $classes[] = $row->plaintext;
         }
         $counter += 1;
     } while (count($classes) == 0 && $counter != 10);
     $class_name = [];
     $class_number = [];
     foreach ($classes as $indice => $value) {
         //DAN DID THIS
         $findPosition = strpos($classes[$indice], '(');
         $subString = rtrim(substr($classes[$indice], 0, $findPosition - 1));
         $class_name[$indice] = $subString;
         $findPosition = strpos($classes[$indice], '(');
         $subString = substr($classes[$indice], $findPosition + 1, 5);
         $class_number[$indice] = $subString;
     }
     //echo 'classes:' . count($class_name);
     $pusher_data = [];
     foreach ($class_name as $indice => $value) {
         $class = SchoolClass::where('class_id', $class_number[$indice])->first();
         if (!$class) {
             $class = SchoolClass::create(['class_name' => $class_name[$indice], 'class_id' => $class_number[$indice]]);
         }
         UserClass::create(['user_id' => $this->user->id, 'class_id' => $class->id, 'priority' => 1]);
         $pusher_data[] = ['class_name' => $class->class_name, 'class_id' => $class->id, 'user_id' => $this->user->id, 'priority' => 1];
     }
     LaravelPusher::trigger('user' . $this->user->id, 'register', ['message' => $pusher_data]);
 }
Example #2
0
 public static function update($user)
 {
     if (!$user->can_fetch()) {
         return [];
     }
     $keys = [];
     $matches = [];
     for ($i = 1; $i <= 4; $i++) {
         // if ($i == 2){
         // echo self::keystone_post(self::SPORTSZONE_URL, $keys, $user);
         // exit;}
         var_dump($i);
         $html = new \Htmldom();
         $html->load(self::keystone_post(self::SPORTSZONE_URL, $keys, $user));
         $keys = static::keys($html);
         $id_matches = [];
         preg_match_all("/p_ID=(.+)}'\\);/", $html->find('img[alt="View Earlier Match"]')[0]->parent()->href, $id_matches);
         $id = $id_matches[1][0];
         $team_name = $html->find('.ms-vb')[0]->find('b')[0]->innertext;
         $opponent_matches = [];
         preg_match_all("/<\\/a>(.+), playing/", $html->find('td[colspan="99"]')[0]->innertext, $opponent_matches);
         if (count($opponent_matches) > 0 && count($opponent_matches[1]) > 0) {
             $opponent_name = $opponent_matches[1][0];
         } else {
             $opponent_name = '';
         }
         $date_matches = [];
         preg_match_all("/<br>Week \\d+, Term \\d, (.+?)(?: - .+)?\$/", $html->find('.ms-vb')[0]->innertext, $date_matches);
         if (count($date_matches) > 0 && count($date_matches[1]) > 0) {
             $date = Carbon::createFromFormat('d/m/Y g:i A', $date_matches[1][0]);
         } else {
             continue;
         }
         $venue_matches = [];
         preg_match_all("/Venue Map -\\s+(.+)/", $html->find('table[cellpadding="2"]')[0]->find('th')[2]->innertext, $venue_matches);
         $venue = $venue_matches[1][0];
         $location_matches = [];
         preg_match_all("/new google\\.maps\\.LatLng\\((-?\\d+.\\d+,-?\\d+.\\d+)\\);/", $html->find('table[cellpadding="2"]')[0]->find('script')[1]->innertext, $location_matches);
         $location = $location_matches[1][0];
         $pre_comments = static::heading_body($html->find('table[cellpadding="2"]')[0], 'Pre-Game Comments');
         $post_comments = static::heading_body($html->find('table[cellpadding="2"]')[1], 'Game Comments');
         $team_list = Person::from_names(array_filter(explode('; ', static::heading_body($html->find('table[cellpadding="2"]')[0], 'Team List'))));
         $staff_list = Person::from_names(array_filter(explode('; ', static::heading_body($html->find('table[cellpadding="2"]')[1], 'Team Staff'))));
         $result = str_replace('<b>Result:</b>&nbsp;', '', $html->find('table[cellpadding="2"]')[1]->find('td')[0]->innertext);
         $table = $html->find('table[width="350px"]');
         $score_self = $table ? $table[0]->find('td')[0]->innertext : '';
         $score_opponent = $table ? $table[0]->find('td')[2]->innertext : '';
         if ($match = Match::find($id)) {
             $match->match_id = $id;
             $match->team_name = $team_name;
             $match->opponent_name = $opponent_name;
             $match->venue = $venue;
             $match->location = $location;
             $match->result = $result;
             $match->date = $date;
             $match->score_self = $score_self;
             $match->score_opponent = $score_opponent;
             $match->pre_comments = $pre_comments;
             $match->post_comments = $post_comments;
             $match->save();
         } else {
             $match = Match::updateOrCreate(array('match_id' => $id, 'team_name' => $team_name, 'opponent_name' => $opponent_name, 'venue' => $venue, 'location' => $location, 'result' => $result, 'date' => $date, 'score_self' => $score_self, 'score_opponent' => $score_opponent, 'pre_comments' => $pre_comments, 'post_comments' => $post_comments));
         }
         $attach = [$user->user_id => 0];
         foreach ($team_list as $index => $person) {
             $attach[$person->person_id] = 1;
         }
         foreach ($staff_list as $index => $person) {
             if (!isset($attach[$person->person_id])) {
                 $attach[$person->person_id] = 2;
             } else {
                 $attach[$person->person_id] += 2;
             }
         }
         foreach ($attach as $user_id => $value) {
             if (!$match->members->contains($user_id)) {
                 $match->members()->attach($user_id, ['is_team' => ($value & 1) == 1, 'is_staff' => ($value & 2) == 2]);
             } else {
                 $match->members()->updateExistingPivot($user_id, ['is_team' => ($value & 1) == 1, 'is_staff' => ($value & 2) == 2]);
             }
         }
         $matches[] = $match;
     }
 }
Example #3
0
 public static function update($user)
 {
     if (!$user->can_fetch()) {
         return [];
     }
     // Add the next fornight's lessons
     $keys = static::keys($user);
     echo "Got authentication keys.\n";
     $lessons = array();
     $date = Carbon::now();
     $periods = [[[8, 35], [8, 45]], [[8, 45], [9, 40]], [[9, 40], [10, 35]], [[10, 55], [11, 45]], [[11, 45], [12, 35]], [[13, 25], [13, 50]], [[13, 50], [14, 40]], [[14, 40], [15, 30]]];
     for ($d = 0; $d < 14; $d++) {
         if (!$date->isWeekend()) {
             echo "Adding: " . $date->toCookieString() . "\n";
             $date_str = $date->format('j/m/Y');
             $html = new \Htmldom();
             $html->load(self::keystone_post(self::TIMETABLE_URL, array('__VIEWSTATE' => $keys['__VIEWSTATE'], '__EVENTVALIDATION' => $keys['__EVENTVALIDATION'], 'ctl00$PlaceHolderMain$ctl00$_uiCurrentDaySel$_uiCurrentDaySelDate' => $date_str), $user));
             $lesson_uls = $html->find('ul[class=TimetableEntry]');
             $start_lesson_n = count($lessons);
             foreach ($lesson_uls as $index => $lesson) {
                 $times_raw = trim($lesson->find('li[class=TimetableEntryLesson]')[0]->innertext);
                 $subject_raw = trim($lesson->find('li[class=TimetableEntryClassName]')[0]->innertext);
                 $location_raw = trim($lesson->find('li[class=TimetableEntryLocation]')[0]->innertext);
                 preg_match_all('/(\\d+:\\d\\d [AP]M) - (\\d+:\\d\\d [AP]M)/', $times_raw, $time_matches);
                 $start = Carbon::createFromFormat('g:i A j/m/Y', $time_matches[1][0] . ' ' . $date_str);
                 $end = Carbon::createFromFormat('g:i A j/m/Y', $time_matches[2][0] . ' ' . $date_str);
                 preg_match_all('/Class: (?:\\d+|\\d+\\w+|\\w+) - (?:(.+)(?:\\s\\d+$|\\s\\w{3}$|\\s\\d+\\w)|(.+))/', $subject_raw, $subject_matches);
                 $subject = strlen($subject_matches[1][0]) == 0 ? $subject_matches[2][0] : $subject_matches[1][0];
                 if (preg_match("/\\d\\dPC/", $subject)) {
                     $subject = "Pastoral Care";
                 }
                 preg_match_all('/Location: (.+)/', $location_raw, $location_matches);
                 $location = $location_matches[1][0];
                 // is a double
                 if ($index != 0 && end($lessons) && end($lessons)['subject'] == $subject) {
                     $lessons[count($lessons) - 1]['end'] = $end;
                 } else {
                     $lessons[] = array('start' => $start, 'end' => $end, 'subject' => $subject, 'location' => $location);
                 }
             }
             $min_period = 0;
             $insert_frees = [];
             for ($index = $start_lesson_n; $index < count($lessons); $index++) {
                 $lesson = $lessons[$index];
                 $start_hour = $lesson['start']->hour;
                 $start_minute = $lesson['start']->minute;
                 $end_hour = $lesson['end']->hour;
                 $end_minute = $lesson['end']->minute;
                 $start_min = $min_period;
                 $found = false;
                 for ($i = $min_period; $i < count($periods); $i++) {
                     $period = $periods[$i];
                     if ($start_hour == $period[0][0] && $start_minute == $period[0][1]) {
                         $min_period = $i + 1;
                         $found = true;
                     } else {
                         if ($end_hour == $period[1][0] && $end_minute == $period[1][1]) {
                             $min_period = $i + 1;
                             $found = true;
                         } else {
                             if (!$found) {
                                 $min_period++;
                                 $end = $lesson['end']->copy();
                                 $end->hour = $period[1][0];
                                 $end->minute = $period[1][1];
                                 if (isset($insert_frees[$index])) {
                                     $insert_frees[$index]['end'] = $end;
                                 } else {
                                     $start = $lesson['start']->copy();
                                     $start->hour = $period[0][0];
                                     $start->minute = $period[0][1];
                                     $insert_frees[$index] = array('start' => $start, 'end' => $end, 'subject' => "Free", 'location' => "");
                                 }
                             } else {
                                 break;
                             }
                         }
                     }
                 }
             }
             $inserted = 0;
             foreach ($insert_frees as $index => $value) {
                 array_splice($lessons, $index + $inserted, 0, array($value));
                 $inserted++;
             }
         }
         $date->addDay();
     }
     // foreach ($lessons as $key => $value) {
     // 	var_dump($value['subject']);
     // 	var_dump($value['start']->toCookieString());
     // }
     echo "Purging old lessons.\n";
     $user->lessons()->delete();
     foreach ($lessons as $index => $lesson) {
         Lesson::updateOrCreate(array('start' => $lesson['start'], 'end' => $lesson['end'], 'subject' => $lesson['subject'], 'location' => $lesson['location'], 'user_id' => $user->user_id));
     }
     echo "Inserted new lessons.\n";
 }
Example #4
0
 function str_get_html($str, $lowercase = true, $forceTagsClosed = true, $target_charset = 'UTF-8', $stripRN = true, $defaultBRText = "\r\n", $defaultSpanText = " ")
 {
     $dom = new Htmldom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);
     if (empty($str) || strlen($str) > 600000) {
         $dom->clear();
         return false;
     }
     $dom->load($str, $lowercase, $stripRN);
     return $dom;
 }
Example #5
0
function parseSimpleContentData($url)
{
    $data = @simplexml_load_file($url, "SimpleXMLElement", LIBXML_NOCDATA);
    $json = json_encode($data);
    $array = json_decode($json, TRUE);
    $output = '';
    $newarray = array_pluck($array, 'item');
    $html = new \Htmldom();
    $html->load($newarray[1][0]['description']);
    echo $newarray[1][0]['description'];
    #$newarray[1][0]['description'];
    dump($newarray);
    foreach ($html->find('font') as $font) {
        foreach ($font->find('font') as $k => $f) {
            if ($k == 2) {
                echo $f->plaintext . '<br><br>';
            }
        }
    }
    #dump($descriptions[0]->plaintext);
}