hagino3000's blog

平成アーカイブス (更新停止)

サイボウズのスケジュールをGrowl通知する

Nodeで取ってきて、growlnotifiyに突っ込んでみた。サイボウズガルーンのAPISOAP(xmlをHTTP POSTで叩けばいい)だけど、ドキュメントが見つからなかったので元々あったライブラリをNodeで動く様に改造して使った。

cybozu-connectがjQueryを使っていたので、jsdomでWindowオブジェクトを作ってjQueryをロードした。

直近30分のスケジュールを取得してGrowlするコードはこんな感じ。
あとは更新のあった掲示板の内容を全てFastladderにぶち込んだりしたい。

#!/opt/local/bin/node

var Cybozu = require('./thirdparty/cybozu-connect.js'),
    growl = require('growl'),
    SETTINGS = require('./settings.js');

Cybozu.init(SETTINGS.JQUERY_PATH, function(API) {
  if (API) {
    growl.notify('Cheking Cybozu schedules.......');

    var con = new API.CybozuConnect.App(SETTINGS.URL, 
                                        SETTINGS.LOGIN_NAME, 
                                        SETTINGS.PASSWORD);

    //console.info('Login info ----------------');
    //console.info(con.user);

    // 直近60分のスケジュールを取得する
    var now = new Date();
    var offset = 1000*60*60;
    var end = new Date(+now + offset);

    var schedule = new API.CybozuConnect.Schedule(con);
    var events = schedule.getEvents({
      start : now,
      end : end,
      userIdList : [con.user.id]
    }, true);

    if (events.users && events.users[con.user.id]) {
      console.info(events.users);
      events.users[con.user.id].forEach(function(s) {
        if (!s.allDay) {
          glowlEvent(s);
        }
      });
    }
  } else {
    console.info('failed to init cybozu api');
  }
});


function glowlEvent(e) {
  var start = new Date(e.start);
  growl.notify(e.title, {
    title: 'Cybozu: ' + start.toLocaleTimeString(),
    sticky: true
  });
}