Created
June 11, 2021 20:05
-
-
Save sell/be175dcd85954f41af94858ca231a3b4 to your computer and use it in GitHub Desktop.
This file contains 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
const { IgApiClient } = require('instagram-private-api'); | |
const ig = new IgApiClient(); | |
ig.state.generateDevice(process.env.USERNAME); | |
(async () => { | |
await ig.simulate.preLoginFlow(); | |
/* | |
Authenticating | |
*/ | |
const auth = await ig.account.login(process.env.USERNAME, process.env.PASSWORD); | |
const followersFeed = ig.feed.accountFollowers(auth.pk); | |
const followingFeed = ig.feed.accountFollowing(auth.pk); | |
/* | |
Getting followers | |
*/ | |
const followers = await getAllItemsFromFeed(followersFeed); | |
/* | |
Getting following | |
*/ | |
const following = await getAllItemsFromFeed(followingFeed); | |
/* | |
Making a new map of users username | |
*/ | |
const users = new Set(followers.map(({ username }) => username)); | |
/* | |
Filtering through the ones who aren't following you | |
*/ | |
const notFollowingYou = following.filter(({ username }) => !users.has(username)) | |
/* | |
Looping through and unfollowing each user; | |
*/ | |
for (const user of notFollowingYou) { | |
/* | |
adding a 1000, so it can always be above 1 seconds delay. | |
*/ | |
const time = Math.round(Math.random() * (6000)) + 1000; | |
setTimeout(async () => { | |
await ig.friendship.destroy(user.pk); | |
console.log(`unfollowed ${user.username}`) | |
}, time) | |
} | |
})(); | |
/* | |
Source: https://github.com/dilame/instagram-private-api/issues/969#issuecomment-551436680 | |
*/ | |
const getAllItemsFromFeed = async (feed) => { | |
let items = []; | |
do { | |
items = items.concat(await feed.items()); | |
} while(feed.isMoreAvailable()); | |
return items; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment