Пример #1
0
 /** 
  * 生成拼音
  */
 public function actionFixpinyin()
 {
     //error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
     $mvBasic = MvBasic::find()->where('id=40')->orderBy('id asc');
     $total = $mvBasic->count();
     $page = 1;
     $pageSize = 40;
     $totalPage = ceil($total / $pageSize);
     $mvBasic->limit($pageSize)->asArray();
     for ($page = 1; $page <= $totalPage; $page++) {
         $offset = ($page - 1) * $pageSize;
         $data = $mvBasic->offset($offset)->all();
         foreach ($data as $v) {
             $basic_id = $v['id'];
             $py_title = PinyinUtil::getFullPy($v['title']);
             $py_title = PinyinUtil::subPinyin($py_title);
             $py_original_title = PinyinUtil::getFullPy($v['original_title']);
             $py_original_title = PinyinUtil::subPinyin($py_original_title);
             try {
                 // 更新
                 $py = MvBasic::findOne($basic_id);
                 $py->py_title = $py_title;
                 $py->py_original_title = $py_original_title;
                 $rs = $py->save();
             } catch (ErrorException $e) {
                 //Yii::warning("Division by zero.");
             }
             echo $rs, ' ', $basic_id, "\n";
         }
         sleep(1);
     }
 }
Пример #2
0
 /**
  * 更新电影基础数据
  */
 public function actionUpdatemovie()
 {
     $mvBasic = MvBasic::find()->where('id>=6214')->orderBy('id asc');
     $total = $mvBasic->count();
     $page = 1;
     $pageSize = 40;
     $totalPage = ceil($total / $pageSize);
     $mvBasic->limit($pageSize)->asArray();
     for ($page = 1; $page <= $totalPage; $page++) {
         $offset = ($page - 1) * $pageSize;
         $data = $mvBasic->offset($offset)->all();
         foreach ($data as $v) {
             $basic_id = $v['id'];
             var_dump('doubanId: ' . $v['douban_id'] . '  basicId: ' . $basic_id . "\n");
             if (empty($v['douban_id'])) {
                 continue;
             }
             $douban_url = 'http://movie.douban.com/subject/' . $v['douban_id'] . '/';
             //$douban_url = 'http://movie.douban.com/subject/10727641/';
             //$basic_id = 1793;
             $html = HttpClient::curlRequset($douban_url);
             if (empty($html)) {
                 continue;
             }
             echo "curl done \n";
             $reg1 = "/<div id=\"info\">[\\s\\S]+?<\\/div>/";
             preg_match($reg1, $html, $info_match);
             if (!isset($info_match['0']) && empty($info_match['0'])) {
                 continue;
             }
             $html_info = $info_match['0'];
             $movie = $this->pregDoubanData($html, $html_info, $v);
             if ($movie) {
                 // 更新
                 $py_title = PinyinUtil::getFullPy($movie['title']);
                 $py_title = PinyinUtil::subPinyin($py_title);
                 $mvBasic1 = MvBasic::findOne(['douban_id' => $v['douban_id']]);
                 //$mvBasic1 = MvBasic::findOne(['douban_id'=>'10727641']);
                 // sub casts
                 $casts = implode(',', $movie['casts']);
                 if (mb_strlen($casts, 'UTF-8') > 255) {
                     $new_casts = mb_substr($casts, 0, 255, 'UTF-8');
                     $new_casts_arr = array_filter(explode(',', $new_casts));
                     $last_cast = end($new_casts_arr);
                     if (!in_array($last_cast, $new_casts_arr)) {
                         array_pop($new_casts_arr);
                     }
                     $casts = implode(',', $new_casts_arr);
                 }
                 $mvBasic1->title = $movie['title'];
                 $mvBasic1->py_title = $py_title;
                 $mvBasic1->rating = $movie['rating'];
                 $mvBasic1->directors = implode(',', $movie['directors']);
                 $mvBasic1->writers = implode(',', $movie['writers']);
                 $mvBasic1->casts = $casts;
                 //$mvBas1ic1->cate = $movie['cate'];
                 $mvBasic1->countries = implode(',', $movie['countries']);
                 $mvBasic1->languages = implode(',', $movie['languages']);
                 $mvBasic1->pubdates = implode(',', $movie['pubdates']);
                 $mvBasic1->durations = implode(',', $movie['durations']);
                 $mvBasic1->aka = implode(',', $movie['aka']);
                 $rs = $mvBasic1->save();
                 if ($rs && $basic_id) {
                     // movie type
                     $movieType = $movie['cate'];
                     $this->updateMovieType($basic_id, $movieType);
                     // country
                     $movieCountry = $movie['countries'];
                     $this->updateMovieCountry($basic_id, $movieCountry);
                 }
                 var_dump($rs);
                 echo "{$v['title']} \n\n";
             }
             //die;
             file_put_contents('./last_id.txt', $v['douban_id'] . '=' . $v['id']);
             sleep(1);
         }
     }
     echo "\n all done \n";
 }