02

2010/09


var targetChannel = "#project";
var fileName = "projectSvnRevision.txt";
//------------------------------------
// 実行時
//------------------------------------
var ret = 0;
function event::onLoad() {
    ret = setInterval(getRssForDev, 1000 * 60 * 10); // by 10 min
    //ret = setInterval(getRssForDev, 1000 * 6); // by 1 min( for test)
}

//------------------------------------
// 時刻チェック
//------------------------------------
function getRssForDev()
{
    var lines = load_textfile_array( fileName );
    var currentRevision = parseInt( lines[0] );
    var req = new ActiveXObject("Microsoft.XMLHTTP");
    if (req) {
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                var s = req.responseText;

                // 2回のタイトル削除
                s.match(/<title>(.*)<\/title>/);
                s = RegExp.rightContext;
                s.match(/<title>(.*)<\/title>/);
                s = RegExp.rightContext;
                
                for (var i=0; i<100; i++) {
                    if (!s.match(/<title>(.*)<\/title>/)) {
                        break;
                    }
                    s = RegExp.rightContext;
                    var title = RegExp.$1;
                    
                    var ret = title.match(/(\d+):/);
                    //var revision = ret[0];
                    var revision = RegExp.$1;
                    //var revision = "";

                    s.match(/<dc:creator>(.*)<\/dc:creator>/);
                    s = RegExp.rightContext;
                    var creator = RegExp.$1;
                    
                    s.match(/<link>(.*)<\/link>/);
                    s = RegExp.rightContext;
                    var link = RegExp.$1;
                    
                    s.match(/<pubDate>(.*)<\/pubDate>/);
                    s = RegExp.rightContext;
                    var pubDate = RegExp.$1;
                    
                    // RSSの最大値を保持しておく
                    if (i == 0) {
                        maxRevision = revision;
                    }
                    
                    if (currentRevision < revision) {
                        send(targetChannel, "====================");
                        send(targetChannel, "TITLE   : " + title);
                        send(targetChannel, "CREATER : " + creator);
                        send(targetChannel, "PUBDATE : " + pubDate);
                        send(targetChannel, "LINK    : " + link);
                     }
                    else {
                        break;
                    }
                    
                }
                
                write_file_string(fileName, maxRevision);
            }
        }
    }
    // ここに読み取りたいURIを記載
    var url = 'http://hogehoge.com/rss'; 

    req.open('get', url, true);
    req.send('');
}

//--------------------------------------------
// ファイル読み込み
//--------------------------------------------
function load_textfile_array( file_name  ){
  lines = new Array();
  d_file = openFile( file_name , true );
    while ( s = d_file.readLine() ) {
      lines[lines.length] = s;
    }
  d_file.close();
  return lines;
}

//--------------------------------------------
// ファイル書き込み
//--------------------------------------------
function write_file_string( file_name, string  ){
    file = openFile( file_name , false );
    file.write(string); 
    file.truncate();
    file.close();
}

これでイけると思うよ。

No Comment.

Add Your Comment