Skip to content

Instantly share code, notes, and snippets.

@teramako
Created August 5, 2010 18:20
Show Gist options
  • Save teramako/510138 to your computer and use it in GitHub Desktop.
Save teramako/510138 to your computer and use it in GitHub Desktop.
twittperatorのChirpUserStreamからのデータをログに書き出す
/*
* このファイルを置いたディレクトリに
* twittperator.log
* を作って、ChirpUserStream からのデータを書き出すよ
* tail -f で見ると良い感じ!!
*/
let charset = "UTF-8";
let os, fos;
function start() {
os = Cc["@mozilla.org/intl/converter-output-stream;1"]
.createInstance(Ci.nsIConverterOutputStream);
let perms = 0644,
mode = io.File.MODE_WRONLY | io.File.MODE_CREATE | io.File.MODE_APPEND;
fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
fos.init(getLogFile(), mode, perms, 0);
os.init(fos, charset, 0, 0x0000);
}
function stop() {
os.close();
fos.close();
}
function getLogFile(){
let logFile = io.File(PATH).parent;
logFile.append("twittperator.log");
return logFile;
}
function log (msg) {
if (!os || !fos)
return;
try {
os.writeString(msg);
} catch (e) {
liberator.log(e);
}
}
plugins.twittperator.ChirpUserStream.addListener(
function onMsg (msg, raw) {
if (msg.text && msg.user) {
log([
msg.user.screen_name + "#" + msg.id,
(new Date(msg.created_at)).toLocaleFormat("%Y-%m-%dT%H:%M:%S"),
msg.text
].join("\t") + "\n");
}
}
);
start();
function onUnload() {
stop();
}
// vim: sw=2 ts=2 et fdm=marker ft=javascript:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment