Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
/*
Quick script for analyzing data from your Facebook activity page
Steps:
1. Go to https://www.facebook.com/me/allactivity?privacy_source=activity_log&log_filter=likedposts
2. Scroll down as far as you want.
3. Open up the browser dev tools, copy the HTML and save it to a file named "sample.html".
4. Make sure you have node.js installed (nodejs.org).
5. Install the cheerio library (type "npm install cheerio" at the command line).
6. Save this script as app.js and run it in the same directory as your saved output (ex: "node app").
*/
var cheerio = require('cheerio'),
fs = require('fs'),
data = fs.readFileSync('sample.html', 'utf8'),
$ = cheerio.load(data),
friend,
friends = {},
ranking = [];
// This class may change
$('._42ef').each(function() {
var links = $(this).find('a'),
name;
if (links.length > 1 && links[1].attribs.class === 'profileLink') {
name = links[1].children[0].data;
friends[ name ] = friends[ name ] || {};
friends[ name ].likes = friends[ name ].likes || 0;
friends[ name ].likes++;
}
});
for (friend in friends) {
if (!friends.hasOwnProperty(friend)) continue;
ranking.push({
name:friend,
likes: friends[friend].likes
})
}
// will put the top entries at the bottom (easier to read when printing on console)
ranking.sort(function(a,b) {
return a.likes - b.likes;
});
var likeCount = 0;
for (var ii = 0; ii < ranking.length; ii++) {
likeCount += ranking[ii].likes;
}
console.dir(ranking);
console.log('total likes: '+likeCount);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment