ホーム > タグ > javascript
javascript
Google Buzz のつぶやきを垂れ流してみた
- 2011-11-28 (月)
- JavaScript
ただの2番煎じですが、google buzz がサービス停止するということで、google buzz のつぶやきをエクスポートしたものをストリームっぽく垂れ流すようにしました。
http://www.toshipon.com/sample/buzz/buzz/index.html
以下で google buzz のつぶやきをエクスポートできます。
https://www.google.com/takeout/
まず、ひとつひとつのつぶたきが日本語名のhtmlファイルなので、ファイル作成日でrenameします。
count = 0
Dir::foreach('./buzz') { |f|
count = count + 1
time = Time.now
from = './buzz/' + f
mt = File::mtime('./buzz/'.concat(f))
to = './buzz/' + format("%04d", mt.year) + format("%02d", mt.month) + format("%02d", mt.day) + format("%02d", mt.min) + format("%02d", mt.sec) + ".html"
if File::ftype(from) == "file"
File::rename from, to
end
}
renameしたhtmlファイルのファイル名を一括でfiles.jsonの中に一覧で取り込み
文字列置換で適当にjsonフォーマットに変換します。
ls >> files.json
その後、jsでhtmlファイルを読み込み垂れ流してみます。
$(function(){
console.log("script.js start");
$.ajax({
url : "http://www.toshipon.com/sample/buzz/buzz/buzz/files.json",
//dataType : "json",
success : function(file){
file = JSON.parse(file);
popBuzz(file);
}
});
var i = 0;
function popBuzz(file) {
if (file.length === i+1){ return; }
setTimeout(function(){
$("#content").prepend($("
").load("http://www.toshipon.com/sample/buzz/buzz/buzz/"+ file[i]));
i++;
if ($('#content li').length > 10){$('#content li:last').remove();}
popBuzz(file);
}, 2000);
}
});
簡単ですね。
ソースはこちら。 https://github.com/toshipon/buzz
- Comments: 0
- Trackbacks: 0
Home > Tags > javascript
- Search
- Feeds
- Meta