Created
August 5, 2010 18:20
-
-
Save teramako/510138 to your computer and use it in GitHub Desktop.
twittperatorのChirpUserStreamからのデータをログに書き出す
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* このファイルを置いたディレクトリに | |
* 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