public function main() { // 先爬 dimensions 最新的 $articles = $this->getFromDimension(); foreach ($articles as $article) { if (!($headlinelog = HeadLineLog::find($article->time))) { HeadLineLog::insert(array('time' => $article->time, 'data' => json_encode($article, JSON_UNESCAPED_UNICODE))); } } // 再從 google 搜尋 ettoday 七天的資料 for ($i = 0; $i < 7; $i++) { $time = strtotime('00:00:00 -' . $i . 'day'); if (HeadLineLog::find($time)) { // 資料庫中已經有了就不用再找了 continue; } try { $article = $this->getFromETTodayByGoogle(date('md', $time)); } catch (Exception $e) { continue; } if (!($headlinelog = HeadLineLog::find($article->time))) { HeadLineLog::insert(array('time' => $article->time, 'data' => json_encode($article, JSON_UNESCAPED_UNICODE))); } } // 再從 中央社粉絲團搜尋 ettoday 七天的資料 for ($i = 0; $i < 30; $i++) { $time = strtotime('00:00:00 -' . $i . 'day'); if (HeadLineLog::find($time)) { // 資料庫中已經有了就不用再找了 continue; } try { $article = $this->getFromCNAFacebookPage($time); } catch (Exception $e) { continue; } if ($article and !($headlinelog = HeadLineLog::find($article->time))) { HeadLineLog::insert(array('time' => $article->time, 'data' => json_encode($article, JSON_UNESCAPED_UNICODE))); } } exit; }
<?php include __DIR__ . '/webdata/init.inc.php'; $article = new StdClass(); $article->title = '0706四大早報頭條 | 要聞 | 即時新聞 | 聯合新聞網'; $article->link = 'http://udn.com/NEWS/BREAKINGNEWS/BREAKINGNEWS1/8010790.shtml'; $article->image_link = ''; $article->time = strtotime('2013/7/06 0:0:0'); $article->headlines = array(array('聯合報', '女雙晉決賽 謝淑薇搶溫網金杯'), array('蘋果日報', '恨爸當眾打頭 少女負氣飆車雙亡'), array('中國時報', '謝淑薇勇闖溫網冠軍賽'), array('自由時報', '府院虛晃一招 劉政鴻:大埔案就是拆')); HeadLineLog::insert(array('time' => $article->time, 'data' => json_encode($article, JSON_UNESCAPED_UNICODE)));