Exemple #1
0
 public function healthAction()
 {
     // 檢查前十天是否有正常抓到資料
     for ($i = 1; $i < 10; $i++) {
         if (!HeadLineLog::find(strtotime('today') - $i * 86400)) {
             echo 'warning';
             exit;
         }
     }
     echo 'ok';
     exit;
 }
Exemple #2
0
    }
    protected function clearPersistentData($key)
    {
        unset($this->_persistent_data[$key]);
    }
    protected function clearAllPersistentData()
    {
        $this->_persistent_data = array();
    }
}
$config = array('appId' => getenv('FB_APPID'), 'secret' => getenv('FB_SECRET'));
$facebook = new MyFacebook($config);
$facebook->setAccessToken(getenv('FB_ACCESSTOKEN'));
$params = array();
$time = strtotime('0:0:0 -30day');
if (!($log = HeadLineLog::find($time))) {
    exit;
}
if ($log->facebook_id) {
    exit;
}
$data = json_decode($log->data);
$message = '';
$message .= '腿新聞為您帶來30天前的四大報頭版:' . date('Y/m/d', $time) . PHP_EOL;
foreach ($data->headlines as $headline) {
    list($paper, $title) = $headline;
    $message .= $paper . ':' . $title . PHP_EOL;
}
for ($i = 0; $i < 3; $i++) {
    $ret = $facebook->api('lagnews.tw/feed', 'post', array('message' => $message, 'link' => $data->link));
    if (!$ret['id']) {
Exemple #3
0
 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;
 }