示例#1
0
 public function actionParse($from = null, $to = null, $id = null, $nocache = null)
 {
     if ($id) {
         $from = $id;
         $to = $id + 1;
     }
     if (!$from) {
         $this->stop("((");
     }
     $flag_working = true;
     $ank_id = intval($from);
     $tries = 0;
     while ($flag_working) {
         if ($ank_id == $to) {
             $this->stop("All done");
         }
         //sleep(2);
         $this->writeln("Parsing {$ank_id}");
         $html = $this->getHtml($ank_id, $nocache == 1 ? false : true);
         if (preg_match('/' . $this->stopWord . '/uism', $html)) {
             $tries++;
             $ank_id++;
             $this->writeln($this->stopWord);
             if ($tries == 5) {
                 return $this->stop("I'm stopping");
             }
             continue;
         } else {
             $tries = 0;
         }
         // parse
         preg_match('/Жизненное\\s+кредо<\\/td>(.+?)<\\/td>/xuism', $html, $matches);
         $ro = preg_replace('/\\s\\s+/', ' ', $matches[0]);
         //var_dump($matches);
         $phone = $this->capturePhone($matches[0]);
         if (!$phone) {
             preg_match('/(Дополнительная\\s+информация\\s+\\(несколько\\s+слов\\s+о\\s+себе\\s+и\\s+своих\\s+увлечениях\\)<\\/td>(.+?)<\\/td>)/xuism', $html, $matches);
             if (isset($matches[0])) {
                 $ro = preg_replace('/\\s\\s+/', ' ', $matches[0]);
                 $phone = $this->capturePhone($matches[0]);
             }
             if (!$phone) {
                 $this->no_phone[] = $this->anketUrl . $ank_id;
                 $this->writeln("no phone");
                 $ank_id++;
                 continue;
             }
         }
         $this->writeln($phone);
         // save
         $phone_model = Phones::model()->findByAttributes(array('phone' => $phone));
         if (!$phone_model) {
             $phone_model = new Phones();
             $phone_model->phone = $phone;
             if (!$phone_model->save()) {
                 $this->stop('failed to save $phone_model');
             }
         }
         $anket_model = Ankets::model()->findByAttributes(array('id' => $ank_id));
         if (!$anket_model) {
             $anket_model = new Ankets();
             $anket_model->id = $ank_id;
             $anket_model->phone_id = $phone_model->id;
             if (!$anket_model->save()) {
                 $this->stop('failed to save $anket_model');
             }
         }
         $ank_id++;
     }
 }
示例#2
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Phones::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }