Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@patorjk
Last active June 20, 2018 00:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patorjk/a0a1a1a67ecdd99524a5 to your computer and use it in GitHub Desktop.
Save patorjk/a0a1a1a67ecdd99524a5 to your computer and use it in GitHub Desktop.
/*
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