Ejemplo n.º 1
0
 public function rssAction()
 {
     $this->view->title = '四大報歷史頭條 RSS';
     $this->view->link = 'http://oldpaper.g0v.ronny.tw';
     $items = array();
     if ($_GET['type'] == 'bypaper') {
         // 依報紙找出某年
         if (!strval($_GET['paper'])) {
             throw new Exception("需要指定 paper={報紙}");
         }
         $paper = $_GET['paper'];
         $year = intval($_GET['year']) ?: date('Y');
         $start = mktime(0, 0, 0, 1, 1, $year);
         $end = mktime(0, 0, 0, 1, 1, $year + 1);
         foreach (HeadLineLog::search("`time` >= {$start} AND `time` < {$end}") as $log) {
             $log = json_decode($log->data);
             foreach ($log->headlines as $headlines) {
                 list($p, $title) = $headlines;
                 if ($p == $paper) {
                     $item = new StdClass();
                     $item->description = $title;
                     $item->time = $log->time;
                     $item->link = $log->link;
                     $items[] = $item;
                 }
             }
         }
     } else {
         // 依月份找出所有
         $year = intval($_GET['year']) ?: date('Y');
         $month = intval($_GET['month']) ?: date('m');
         $start = mktime(0, 0, 0, $month, 1, $year);
         $end = strtotime('+1 month', $start);
         foreach (HeadLineLog::search("`time` >= {$start} AND `time` < {$end}") as $log) {
             $log = json_decode($log->data);
             foreach ($log->headlines as $headlines) {
                 list($p, $title) = $headlines;
                 $item = new StdClass();
                 $item->description = $title;
                 $item->time = $log->time;
                 $item->link = $log->link . '#' . $p;
                 $items[] = $item;
             }
         }
     }
     $this->view->items = $items;
 }
Ejemplo n.º 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']) {
Ejemplo n.º 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;
 }
Ejemplo n.º 4
0
<?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)));