Instapy: unfollow_by_list() function

Created on 11 Feb 2018  路  8Comments  路  Source: timgrossmann/InstaPy

Is there a way to unfollow users by a list?

wontfix

Most helpful comment

Do I have to change the InstaPy source code?

All 8 comments

yes it is very easy to do,
just add a new argument to unfollow_users() method, and add a new condition to unfollow() function in unfollow_util.py
then pass user list, to that statement...

Do I have to change the InstaPy source code?

Yes, actually you are adding a new parameter!

Follow these steps

1. open instapy.py file, find def unfollow_users( and add your new parameter UnfollowByList

it will be like this

def unfollow_users(self,
                       amount=10,
                       onlyInstapyFollowed=False,
                       onlyInstapyMethod='FIFO',
                       sleep_delay=600,
                       onlyNotFollowMe=False,
                       UnfollowByList=None):       #new parameter here

2. Modify that method

        """Unfollows (default) 10 users from your following list"""
        if onlyInstapyFollowed == True:    #only generate FollowedPool in onlyInstaPyFollowed method
            self.automatedFollowedPool = set_automated_followed_pool(self.username,
                                                                     self.logger,
                                                                     self.logfolder)
        try:
            unfollowNumber = unfollow(self.browser,
                                      self.username,
                                      amount,
                                      self.dont_include,
                                      onlyInstapyFollowed,
                                      onlyInstapyMethod,
                                      self.automatedFollowedPool,
                                      sleep_delay,
                                      onlyNotFollowMe,
                                      self.logger,
                                      self.logfolder,
                                      UnfollowByList)      #pass your new parameter to unfollow utility

3. Edit unfollow() function in unfollow_util.py to have UnfollowByList parameter

def unfollow(browser,
             username,
             amount,
             dont_include,
             onlyInstapyFollowed,
             onlyInstapyMethod,
             automatedFollowedPool,
             sleep_delay,
             onlyNotFollowMe,
             logger,
             logfolder,
             UnfollowByList):     #new parameter here

4. Enable unfollow() function to do unfollowing by list

so, find if onlyInstapyFollowed is True: in unfollow_util.py file and add these lines before it (beware of indentation)
get it here (cos of Github messes with indentation, I pastebinned it)

@lovePizza
_use it like this_...

session.unfollow_users(UnfollowByList=['first_user', 'second_unfllow', 'other user', 'blah_blah'], amount=100, onlyInstapyFollowed=False, onlyInstapyMethod='FIFO', sleep_delay=600, onlyNotFollowMe=False)

it will unfollow every user in the list _you give_ (if you really are following them...)
and it will not care the amount you give it in there

if you don't want to use UnfollowByList method some other time, give it a None value or just remove it from session.unfollow_users()

i haven't tested, if something is not working as expected, please, let me know :-)

Thanks, it works, I only had to set "amount=0" in the "session.unfollow_users" function

Thanks a lot @uluQulu ! Works great.

Remember to change if onlyInstapyFollowed is True: to elif onlyInstapyFollowed is True:

Otherwise it will continue its regular unfollowing routine and unfollow X people from your account. Of course you can just set amount=0 as @lovePizza mentions.

Nice guys,
I didn't touch it to follow style of unfollow_users()

enable what you wanna use, othervise set them to False

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this problem still occurs, please open a new issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tibor picture tibor  路  3Comments

harrypython picture harrypython  路  3Comments

wyvers picture wyvers  路  3Comments

Spyd3r0us picture Spyd3r0us  路  3Comments

CharlesCCC picture CharlesCCC  路  3Comments