Skip to content

Instantly share code, notes, and snippets.

@vittau
Created October 1, 2024 20:00
Show Gist options
  • Save vittau/a65c5ee99e28d44c98b2bc219e8d3b93 to your computer and use it in GitHub Desktop.
Save vittau/a65c5ee99e28d44c98b2bc219e8d3b93 to your computer and use it in GitHub Desktop.
Users who don't follow back on Instagram (use exported data as JSON)
const fs = require("fs");
// Function to read JSON files
function readJsonFile(filePath) {
return new Promise((resolve, reject) => {
fs.readFile(filePath, "utf8", (err, data) => {
if (err) {
reject(err);
} else {
resolve(JSON.parse(data));
}
});
});
}
// Function to find the set difference
function findSetDifference(following, followers) {
const followingSet = new Set(following);
const followersSet = new Set(followers);
return followingSet.difference(followersSet);
}
// Main function to read files and print the set difference
async function main() {
try {
const fileFollowing = await readJsonFile("following.json").relationships_following;
const fileFollowers = await readJsonFile("followers_1.json");
const following = fileFollowing.map((i) => i.string_list_data[0].value);
const followers = fileFollowers.map((i) => i.string_list_data[0].value);
const difference = findSetDifference(following, followers);
console.log('People in "following" not in "followers":', difference);
} catch (error) {
console.error("Error reading files:", error);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment