thiagowfx's avatar

Β¬ just serendipity πŸ€ (not just serendipity)

Instagram: unfollow non-followers

β€’ 558 words β€’ 3 min β€’ updated

Sometimes connections simply fade away. Life happens. Privacy prevails. Then why don’t people remove them both ways (follower + following)? If you don’t want to stay connected with someone any longer, it is good courtesy to do so symmetrically. If you just unfollow someone, without removing them from your follower list, then you tacitly demonstrate that you care to a great extent about invisible internet karma points /shrug.

Instagram doesn’t make it easy to find those who do not follow you back. However, it is possible to obtain this information with a little bit of scripting.

shell
% tree connections
connections
└── followers_and_following
    β”œβ”€β”€ blocked_profiles.json
    β”œβ”€β”€ close_friends.json
    β”œβ”€β”€ follow_requests_you've_received.json
    β”œβ”€β”€ followers_1.json
    β”œβ”€β”€ following.json
    β”œβ”€β”€ hide_story_from.json
    β”œβ”€β”€ pending_follow_requests.json
    β”œβ”€β”€ profiles_you've_favorited.json
    β”œβ”€β”€ recent_follow_requests.json
    β”œβ”€β”€ recently_unfollowed_profiles.json
    └── removed_suggestions.json

(Yes, one of these files has a ' in the name. It was not a typo.)

We’re interested in followers_N.json and following.json.

From this point on, vibe code and chill. A single, well-crafted prompted is enough. For example:

You are a world-class software developer.

I exported all my Instagram data.

Write a python script to parse all people I follow that do not follow me back.

Output username + profile URLs in each line.

I am a fan of this one-shot prompt structure / style2:

  • you are a superb ${FOO}
  • this is some context for you
  • do this for me
  • output in the desired format

The resulting script:

python
#!/usr/bin/env python3

import json
import csv
from pathlib import Path

# Base path where your JSON files are
base = Path("connections/followers_and_following")

def extract_usernames(file_path):
    """Extract Instagram usernames from a followers/following JSON file."""
    with open(file_path) as f:
        data = json.load(f)

    # Handle both old and new formats
    if isinstance(data, dict):
        for v in data.values():
            if isinstance(v, list):
                data = v
                break

    if not isinstance(data, list):
        raise ValueError(f"Unexpected format in {file_path}")

    usernames = set()
    for item in data:
        try:
            entry = item.get("string_list_data", [])[0]
            username = (
                entry.get("value")
                or entry.get("href", "").rstrip("/").split("/")[-1]
                or entry.get("username")
            )
            if username:
                usernames.add(username)
        except Exception:
            continue

    return usernames


# --- Load followers (handles multiple files) ---
followers = set()
for path in base.glob("followers_*.json"):
    followers |= extract_usernames(path)

# --- Load following ---
following = extract_usernames(base / "following.json")

# --- Compute differences ---
not_following_back = sorted(following - followers)
you_dont_follow_back = sorted(followers - following)
mutuals = sorted(followers & following)

def write_csv(filename, users):
    with open(filename, "w", newline="", encoding="utf-8") as f:
        writer = csv.writer(f)
        writer.writerow(["username", "profile_url"])
        for user in users:
            writer.writerow([user, f"https://www.instagram.com/{user}/"])
    print(f"βœ… Saved {len(users)} entries to {filename}")

# --- Write results ---
write_csv("not_following_back.csv", not_following_back)
write_csv("you_dont_follow_back.csv", you_dont_follow_back)
write_csv("mutuals.csv", mutuals)

The script was tested in a real account, and I’m pleased to state that it works as intended.

If you use it for the sake of unfollowing people3 then it’s advisable not to automate the unfollowing process, as Instagram could potentially block you. Instead, do it manually.

May the reduced noise increase your serenity.


  1. Or else it won’t work. ↩︎

  2. I am not here to claim what prompt is the best. Just keep it simple and carry on. ↩︎

  3. Why would you run it otherwise? ↩︎