Check out this code snippet I created, it might spark some ideas:
http://jsfiddle.net/TgTtV/
lastDate = false;
setInterval(function() {
function compareDates (argument) {
return (new Date(argument.created_at) > lastDate);
}
jQuery.ajax({
url: 'http://search.twitter.com/search.json',
type: 'GET',
dataType: 'jsonp',
data: {q: encodeURIComponent('#test')},
success: function(data, textStatus, xhr) {
//If it's the first time running, prepend all tweets to the page
if(!lastDate) {
for(i in data.results) {
$('body').prepend('<p>'+data.results[i].from_user+': '+data.results[i].text+'</p>');
}
} else { //Only new tweets, filtered by date are added
var newMessages = data.results.filter(compareDates);
//Just for test
console.log(newMessages);
for(i in newMessages) {
$('body').prepend('<p>'+newMessages[i].from_user+': '+newMessages[i].text+'</p>');
}
}
lastDate = new Date(data.results[0].created_at);
}
});
}, 10000);
Explanation:
This code snippet loads tweets based on a specific query (in this case, the hashtag #test), displaying the username and tweet content in paragraphs. It continues to load new tweets after the initial load, filtering them by date using the compareDates function and only showing new tweets on the page.
For better understanding, try testing this snippet with Firebug's console open.