Filter Instagram Following Lists with this Future-proof Method

Getting followers for the Maker WS Instagram is a daily grind. Besides having quality content (I’m working on it), the most effective way to get followers is the follow/unfollow method. Eventually, though, I found that my follower to following ratio was a little embarrassing, so I needed to find a way to filter my Instagram following list and weed out those accounts that weren’t following me.

Unfortunately, Instagram doesn’t provide an easy way to compare your follower and following lists. You could jump back and forth between the list trying to see if someone you are following is following you, but that would be very tedious.

via GIPHY

There’s got to be a better way.

Yes, there are many apps that will help you sort through these two lists. However, most of the good ones are not free. Also, using these apps violates Instagram’s terms of service.

Even if you are comfortable paying for and using one of those apps, there is a big change coming on June 29th of this year with Instagram deprecating their old API and many of those old apps won’t work anymore.

So, I set out to find a very low-tech solution to keep my following list slim. Keep reading for my Python script that will show you accounts that are not following you.


Who this article is for

You’ll need to have a PC that has Python version 3.X installed and have text editor where you can save the script. You won’t need to install any libraries, so there’s no need for a virtual environment.

If you are the type of Instagrammer that maxes out your following quota every day, then this guide probably isn’t for you. I look for people to follow that might be interested in my projects like my OBS recording sign or my live LED cam, so I only end up following a few dozen accounts a day.

The method used in this article to filter Instagram following lists will not work if you are looking to cut hundreds of followers a day!

Scraping your lists

I wasn’t joking when I said low-tech. This first step was made possible by the great Larry Tesler, the inventor or ctrl-c ctrl-v, may he rest in peace. We are simply going to log into Instagram on a PC and copy and paste the two lists.

Copying Instagram following list

I like to start at the bottom of the list and select up to the top. Everything on the left side of the pop-up should be highlighted.

Using your text editor of choice (not Word!), save each list in its own text file. I’m going to call mine followers.txt and following.txt. Make sure the first line of each file contains the words ‘profile picture’. If it doesn’t, try copying and pasting again.

Pasting Instagram following list

That’s it. Now its time for some string processing with Python.

Find non-followers with Python

This is a fairly simple Python script, but I’ll explain it anyway. I am not an expert and if you know a better way to code this script, please tell me in the comments. You can find the full script below.

We’ll start out by importing argparse and define a few command-line arguments. We’ll use these arguments to specify which files to use with the script.

import argparse

ap = argparse.ArgumentParser()
ap.add_argument("-r", "--followers", required=True, help="path to follower list")
ap.add_argument("-g", "--following", required=True, help="path to following list")
ap.add_argument("-o", "--output", required=True, help="path to output file")
args = vars(ap.parse_args())

Next, let’s initialize a few lists to store our account names in.

followers = list()
following = list()
not_followers = list()

Here is where the action starts. Each user we copied from our Instagram lists takes up two or three lines of text. The first line is the account name followed by “‘s profile picture”. The next line is their username, and if they specified a real name it will be on the third line.

We don’t know how many lines of text any given account will use, but we do know that a line after a line that contains the string ‘profile picture’ is sure to be an account name. So the following function looks for the picture string and adds the next line to the right list.

def strip_text(text_file, target_list):
    with open(text_file, 'r') as f:
        for line in f:
            if 'profile picture' in line:
                target_list.append(f.readline())

Both of our lists follow the same format, so we can use the strip_text() function we made on both of them. We just need to specify the correct list to store the account names in.

strip_text(args['followers'], followers)
print(str(len(followers)) + ' followers found.')
strip_text(args['following'], following)
print(str(len(following)) + ' accounts following found.')

Filter the Instagram following list

Now, let’s compare the two lists with a nested loop. We’ll check if each account from the following list is also in the followers list. If it is, nothing will happen. If it’s not, then that account will be added to the not_following list.

for account in following:
    account_is_following = False
    for follower in followers:
        if account == follower:
            account_is_following = True
            break
    if not account_is_following:
        not_followers.append(account)

Finally, write the non-followers to a file.

output = open(args['output'], 'w')

for not_follower in not_followers:
    output.writelines(not_follower)

output.close()

You will need to have Python 3 installed on your computer for the next step. Assuming your two Instagram list files and the python script are in the same directory, to run the program use the following command (your file names may be different):

python3 filterFollowers.py -r followers.txt -g following.txt -o output.txt

You should see output like this:

Output from follower filter script

Now that you have a list of accounts that are not following you, it’s time to head to Instagram and start unfollowing. Remember to sort from earliest to newest in the app! You don’t want to unfollow someone who hasn’t had a chance to follow you back. And remember not to unfollow too many people in one day!

Here is the complete code:

import argparse

ap = argparse.ArgumentParser()
ap.add_argument("-r", "--followers", required=True, help="path to follower list")
ap.add_argument("-g", "--following", required=True, help="path to following list")
ap.add_argument("-o", "--output", required=True, help="path to output file")
args = vars(ap.parse_args())

followers = list()
following = list()
not_followers = list()

def strip_text(text_file, target_list):
    with open(text_file, 'r') as f:
        for line in f:
            if 'profile picture' in line:
                target_list.append(f.readline())

strip_text(args['followers'], followers)
print(str(len(followers)) + ' followers found.')
strip_text(args['following'], following)
print(str(len(following)) + ' accounts following found.')

for account in following:
    account_is_following = False
    for follower in followers:
        if account == follower:
            account_is_following = True
            break
    if not account_is_following:
        not_followers.append(account)

print(str(len(not_followers)) + ' accounts that you are following are not following you.')

output = open(args['output'], 'w')

for not_follower in not_followers:
    output.writelines(not_follower)

output.close()

Leave a Comment

Your email address will not be published. Required fields are marked *