Last active
October 25, 2015 18:36
-
-
Save coleww/d4114c307f3b260d4c90 to your computer and use it in GitHub Desktop.
bot stats
This file contains hidden or 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 config = require({CONFIG_IN_THE_TTEZEL/TWIT_MODULE_STYLE}) | |
var Twit = require('twit') | |
var T = new Twit(config) | |
var fs = require('fs') | |
var uname = 'YR-TWITTER-USERNAME' | |
var listSlug = 'THE-SLUG-TO-YR-BOT-LIST' | |
var theInterval = 5000 | |
// Requests / 15-min window (user auth) // 180 | |
// if yr list has > 180 members, uhhhhh increase theInterval so that it doesn't break 180 in 15 minutes? | |
// eventually, turn this into a node module or whatever | |
// module.exports = function (config) { | |
// config.twit | |
// config.uname | |
// config.listname | |
// config.interval | |
// config.fetch | |
// } | |
T.get('lists/members', {slug: listSlug, owner_screen_name: uname, count: 5000}, function (err, members, response) { | |
console.log(err) | |
var botStats = members['users'].map(function (u) { | |
return { | |
sn: u.screen_name, | |
followers: u.followers_count , | |
statuses: u.statuses_count, | |
id: u.id_str, | |
lastStatus: u.status.text, | |
lastTweeted: u.status.created_at | |
} | |
}) | |
var inty | |
var stats = [] | |
inty = setInterval(function () { | |
var current = botStats.pop() | |
if (current) { | |
console.log('doing', current.sn) | |
T.get('statuses/user_timeline', {count: 200, user_id: current.id}, function (e, d, r) { | |
if (d) { | |
var recent_stats = d.map(function (tweet) { | |
return {fave: tweet.favorite_count || 0, | |
rt: tweet.retweet_count || 0} | |
}).reduce(function(o, e) { | |
o.fave += e.fave | |
o.rt += e.rt | |
return o | |
}, {fave: 0, rt: 0}) | |
current.fave = recent_stats.fave | |
current.rt = recent_stats.rt | |
} | |
console.log(current) | |
stats.push(current) | |
}) | |
} else { | |
clearInterval(inty) | |
fs.writeFileSync('./botStats' + (new Date()).toString() + '.txt', JSON.stringify(stats)) | |
} | |
}, theInterval) | |
}) |
This file contains hidden or 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
// for each bot on yr bot list, you'll get a lil object that looks like this: | |
{ sn: 'gutenScrum', | |
followers: 57, | |
statuses: 337, | |
id: '3013772461', | |
lastStatus: 'Yesterday I got easy again. Today I will advise you and direct you. No blockers.', | |
lastTweeted: 'Fri Oct 23 17:00:06 +0000 2015', | |
fave: 3, | |
rt: 14 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment