Example #1
0
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);
    }
}
#如果是周五也执行今天的, 并发邮件, 提醒
Example #2
0
 * @author    TX <*****@*****.**>
 * @link    http://blog.txthinking.com
 * @license    http://www.gnu.org/licenses/old-licenses/gpl-2.0.html     GNU GPL v2
 * @version 0.9
 */
$username = $argv[1];
$password = $argv[2];
$sound = '/home/tx/Music/gmail-sound.wav';
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://mail.google.com/mail/feed/atom/');
$txsr->setUserPwd($username, $password);
$result = $txsr->send();
//处理
$txs = new TX_String();
$txs->setString($result);
$mailInfo = $txs->getByRegular('/<entry>[\\S\\s]*?<title>(.*)<\\/title>[\\S\\s]*?<name>(.*)<\\/name>[\\S\\s]*?<email>(.*)<\\/email>[\\S\\s]*?<\\/entry>/');
//$mailInfo[0] 所有邮件数组 $mailInfo[1] 所有标题数组 $mailInfo[2] 所有发件人姓名 $mailInfo[3] 所有发件人email
$mailCount = count($mailInfo[0]);
//未读邮件数
if ($mailCount > 0) {
    $outputTitle = "旭哥, 有 {$mailCount} 封新邮件!";
    $outputcontent = '';
    for ($i = 0; $i < $mailCount; $i++) {
        $outputcontent .= $mailInfo[1][$i] . "  ::  " . $mailInfo[2][$i] . "\n";
    }
    $command = "env DISPLAY=:0.0 notify-send \"{$outputTitle}\" \"{$outputcontent}\" && aplay {$sound} 2>/dev/null";
    //如果需要声音提示在$command后面加上 && aplay /home/tx/Music/大地.mp3 2>/dev/null
    exec($command);
}