Simple
node client to import the public twitter timeline into couchdb running at http://127.0.0.1:5984/ (create the database at /twitter/ first).
Everybody can run 150 public API requests per hour which nets you around 3000 tweets per hour. The client polls the public API every 0.5 seconds.
Runs against 2010.07.16 node-v0.1.101.
#!/usr/bin/env node
var http = require('http');
var couch = http.createClient(5984, '127.0.0.1');
var twitter = http.createClient(80, 'api.twitter.com');
function post_all_json(twitter_json_text) {
var creq = couch.request('POST', '/twitter/_bulk_docs',
{'content-type': 'application/json'});
creq.write('{"docs":' + twitter_json_text + '}');
creq.end();
}
function runTwitterRequest() {
var treq = twitter.request('GET', '/1/statuses/public_timeline.json',
{'host': 'api.twitter.com'});
treq.end();
treq.on('response', function(response) {
var twitter_response = "";
response.setEncoding('utf8');
response.on('data', function(chunk) {
twitter_response += chunk;
});
response.on('end', function() {
var tjson = JSON.parse(twitter_response);
console.log("Posting retrieved tweets which number " + tjson.length);
post_all_json(twitter_response);
});
});
}
setInterval(runTwitterRequest, 500);