Created
February 4, 2012 06:57
-
-
Save thebigbad/1735965 to your computer and use it in GitHub Desktop.
download all public tweets of a twitter user
This file contains 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
var http = require('http'), | |
querystring = require('querystring'), | |
fs = require('fs'); | |
var screenname = '5000lobsters'; | |
fs.mkdirSync(process.cwd() + '/tweets'); | |
var getTweets = function(screenname, page) { | |
page = page || 0; | |
var query = { | |
screen_name: screenname, | |
page: page, | |
include_rts: false, | |
trim_user: true | |
}; | |
var options = { | |
host: 'api.twitter.com', | |
port: 80, | |
path: '/1/statuses/user_timeline.json?' + querystring.stringify(query) | |
}; | |
http.get(options, function(res) { | |
res.setEncoding('utf8'); | |
var body = ''; | |
res.on('data', function(data) { | |
body += data; | |
}); | |
res.on('end', function() { | |
var tweets = JSON.parse(body); | |
if (!tweets.length) { | |
return; | |
} | |
tweets.forEach(function(tweet) { | |
var path = [process.cwd(), 'tweets', tweet.id_str + '.json'].join('/'); | |
console.log | |
fs.writeFileSync(path, JSON.stringify(tweet)); | |
}); | |
getTweets(screenname, page + 1); | |
}); | |
}); | |
}; | |
getTweets(screenname); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment