import 'dotenv/config' ; import { IgApiClient , Feed } from '../src' ; const ig = new IgApiClient ( ) ; ig . state . generateDevice ( process . env . IG_USERNAME ) ; ( async ( ) => { await ig . account . login ( process . env . IG_USERNAME , process . env . IG_PASSWORD ) ; const followersFeed = ig . feed . accountFollowers ( ig . state . cookieUserId ) ; const followingFeed = ig . feed . accountFollowing ( ig . state . cookieUserId ) ; const followers = await getAllItemsFromFeed ( followersFeed ) ; const following = await getAllItemsFromFeed ( followingFeed ) ; const followersUsername = new Set ( followers . map ( ( { username } ) => username ) ) ; const notFollowingYou = following . filter ( ( { username } ) => ! followersUsername . has ( username ) ) ; for ( const user of notFollowingYou ) { await ig . friendship . destroy ( user . pk ) ; console . log ( `unfollowed ${ user . username }` ) ; const time = Math . round ( Math . random ( ) * 6000 ) + 1000 ; await new Promise ( resolve => setTimeout ( resolve , time ) ) ; } } ) ( ) ; param feed returns async function getAllItemsFromFeed < T > ( feed ) { let items = [ ] ; do { items = items . concat ( await feed . items ( ) ) ; } while ( feed . isMoreAvailable ( ) ) ; return items ; }