Exemplo n.º 1
0
$sound = '/home/tx/Music/gmail-sound.wav';
$storeFile = "/home/tx/workspace/temp/Data/GoogleCalendarChecker";
if (!file_exists($storeFile)) {
    touch($storeFile);
}
require_once '/home/tx/workspace/tx/php/classes/TX_Http_Curl.php';
require_once '/home/tx/workspace/tx/php/classes/TX_String.php';
$txsr = TX_Http_Curl::getInstance();
$txsr->setUrl('https://www.google.com/calendar/feeds/amaenc22lrakak72hvrj00rhms%40group.calendar.google.com/private-14909f4996a58cfafe08f8f659137e0e/basic?hl=en');
$txsr->setUserPwd($username, $password);
$result = $txsr->send();
//echo $result;exit; //取得最近25条数据
#处理
$txs = new TX_String();
#分离entry
$txs->setString($result);
$regular = "/\\<entry\\>[\\S\\s]*?\\<\\/entry\\>/";
$entrys = $txs->getByRegular($regular);
#执行昨天的
$time = strtotime("-1 day");
$timeRegular = sprintf("%s %s %d, %d", date("D", $time), date("M", $time), date("j", $time), date("Y", $time));
$regular = "/<entry>[\\S\\s]*?<title type='html'>([\\S\\s]*?)<\\/title>[\\S\\s]*?<content type='html'>When: ({$timeRegular})[\\S\\s]*?(Event Description: ([\\S\\s]*?))?<\\/content>[\\S\\s]*?<\\/entry>/";
foreach ($entrys[0] as $v) {
    $txs->setString($v);
    $event = $txs->getByRegular($regular);
    //var_dump($event[1], $event[2], $event[3], $event[4]);exit;
    // 2 日期, 1 title, 4 描述
    for ($i = 0; $i < count($event[1]); $i++) {
        $line = sprintf("[%s]<br/>\n%s<br/><br/>\n\n", $event[2][$i], $event[1][$i]);
        file_put_contents($storeFile, $line, FILE_APPEND | LOCK_EX);
    }