nickpettican / InstaBot

:robot: Automate your Instagram activity with InstaBot, a customisable bot that likes, follows and comments
Apache License 2.0
221 stars 51 forks source link

Set unfollow parameters? #15

Closed ghost closed 7 years ago

ghost commented 7 years ago

Is it possible to set the bot to unfollow everyone who is following more than 2000 accounts?

IE

bot scrapes followings>unfollows accounts with more than 2000 following

nickpettican commented 7 years ago

Yes it's possible @inhaletime, I'll give you a quick and easy way (although this won't cover 100% of the people you follow). Luckily if you've been running the bot for a while you'll have a large following list in profile.json. Here's what you can do:

Here's the script to do this:

from json import load
from csv import writer

with open('profile.json') as dataFile:
   profile = load(dataFile)

usersUnfollow = [[user['user_id']] for user in profile['follows'] if user['follows'] > 2000]

with open('unfollowTheseIDs.csv', 'wb') as out:
   w = writer(out)
   w.writerows(usersUnfollow)
ghost commented 7 years ago

Amazing Nick, Im having so much fun learning Python with people like you in this community. Now let see if I can figure out how to sort the .json file. and pull out the user names.

nickpettican commented 7 years ago

No problem!

If you have a large list of usernames you could even play around with check_user() in instaFunctions.py to get their IDs and include them in following.csv in /cache, and they will be unfollowed when you run the bot.

Note that check_user() takes a requests.Session() object with a desktop user agent (you can find out how to do this in start_requests() in instabot.py), the user URL https://www.instagram.com/%s/ and a username.