Skip to content

Instantly share code, notes, and snippets.

@peny
Created November 12, 2012 15:57
Show Gist options
  • Save peny/4060152 to your computer and use it in GitHub Desktop.
Save peny/4060152 to your computer and use it in GitHub Desktop.
Optimal twitter post time
var fs = require('fs');
var http = require('http');
var _ = require('underscore');
function getTimeline(screen_name, callback) {
//Create an array with one array for each hour of the week
var hours = [];
_.each(_.range(168), function(hour) {
hours.push([]);
});
http.get('http://api.twitter.com/1/statuses/user_timeline.json?count=200&screen_name=' + screen_name, function(res) {
var all_tweets = JSON.parse(res);
_.each(all_tweets, function(tweet) {
var d = new Date(tweet.created_at);
var hour = (d.getDay() * 24) + d.getHours();
hours[hour].push(tweet);
});
var data = _.map(hours, function(tweets, num) {
var retweets = 0;
retweets += (parseInt(_.pluck(tweets, 'retweet_count'), 10) || 0);
return {
retweets: retweets,
total_tweets: tweets.length,
hour: num
};
});
callback(null, data);
})
}
//cdnjs.cloudflare.com/ajax/libs/flot/0.7/jquery.flot.min.js​​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment