Skip to content

Instantly share code, notes, and snippets.

@vilmibm
Created May 9, 2011 20:27
Show Gist options
  • Save vilmibm/963318 to your computer and use it in GitHub Desktop.
Save vilmibm/963318 to your computer and use it in GitHub Desktop.
backup your tweets as XML
var fs = require('fs');
var http = require('http');
function sprintf(str,args) {if(args.length===0)return str;return sprintf(str.replace(/%s/,args[0]),args.splice(1));}
var page = 104;
var streams = {};
var username = process.argv[2] || 'nate_smith';
while (page > 0) {
console.log("page: "+page);
var callback = (function(p) {
var locpage = p;
return function(res) {
console.log("key: " + locpage);
res.on('data', function(chunk) {
streams[locpage].write(chunk);
});
}
})(page);
streams[page] = fs.createWriteStream(sprintf('tweets/%s.xml', [page]), {flags:'a'});
http.get({
host: 'api.twitter.com',
path: sprintf('/1/statuses/user_timeline.rss?screen_name=%s&page=%s', [username, page]),
port: 80
}, callback);
page = page - 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment