Skip to content

Instantly share code, notes, and snippets.

@CxrlosKenobi
Last active September 28, 2022 02:02
Show Gist options
  • Save CxrlosKenobi/224dd9d5ed2c96bbb8aba99636717bc7 to your computer and use it in GitHub Desktop.
Save CxrlosKenobi/224dd9d5ed2c96bbb8aba99636717bc7 to your computer and use it in GitHub Desktop.
Knowing who don't follow you back on Instagram with Python
from getpass import getpass
import instaloader
import os, time
#
USERNAME = input("Username: ")
PWD = getpass("Password: ")
web = instaloader.Instaloader()
print("#\n[ -- ] Logging in ...")
try:
web.login(USERNAME, PWD)
except instaloader.exceptions.TwoFactorAuthRequiredException:
print("#\n[ ! ] Two Factor Authentication Detected")
CODE = input("[ -- ] Type down your 2FA code or simply deactivate it: ")
web.two_factor_login(CODE)
finally:
print("\n[ OK ] Logged in as", USERNAME + "\n")
profile = instaloader.Profile.from_username(web.context, USERNAME)
if not os.path.exists("_metadata"): # Create a folder to store metadata
os.mkdir("_metadata")
## Followees (users that I follow)
try: # Retrieving
with open(f"_metadata/{USERNAME}_followees.txt", "r") as file:
following = file.read().splitlines()
print("[ OK ] Retrieved following list from file.")
except FileNotFoundError: # Creating
print("[ -- ] Retrieving followees ...")
start_time = time.time()
following = [followee.username for followee in profile.get_followees()]
with open(f"_metadata/{USERNAME}_followees.txt", "w") as file:
for followee in following:
file.write(followee + "\n")
end_time = time.time()
elapsed = round(end_time - start_time, 2)
print(f"[ OK ] Retrieved {len(following)} followees in {elapsed} seconds.")
## Followers (users that follow me)
try: # Retrieving
with open(f"_metadata/{USERNAME}_followers.txt", "r") as file:
followers = file.read().splitlines()
print("[ OK ] Retrieved followers list from file.\n")
except FileNotFoundError: # Creating
print("[ -- ] Retrieving followers ...")
start_time = time.time()
followers = [follower.username for follower in profile.get_followers()]
with open(f"_metadata/{USERNAME}_followers.txt", "w") as file:
for follower in followers:
file.write(follower + "\n")
end_time = time.time()
elapsed = round(end_time - start_time, 2)
print(f"[ OK ] Retrieved {len(followers)} followers in {elapsed} seconds.\n")
## Unfollowers (users that I follow but do not follow me back)
unfollowers = [user for user in following if user not in followers]
print(f"[ OK ] {len(unfollowers)} users that you follow, but do not follow you back.")
with open(f"_metadata/{USERNAME}_unfollowers.txt", "w") as file:
for unfollower in unfollowers:
file.write(unfollower + "\n")
## Non-followers (users who follow you but you don't follow back)
nonfollowers = [user for user in followers if user not in following]
print(f"[ OK ] {len(nonfollowers)} users who follow you, but you do not follow them back.")
with open(f"_metadata/{USERNAME}_nonfollowers.txt", "w") as file:
for nonfollower in nonfollowers:
file.write(nonfollower + "\n")
print("\n[ OK ] All done.")
print("[ ! ] Check the _metadata folder for the results.")

Knowing who don't follow you back on Instagram with Python

Step-by-step

1. Install dependencies

First of all you must install the Instaloader library with pip for your python version.

pip install instaloader

2. Run the script

Then you can simply fill the asked input with your credentials and run the script.

python app.py

3. Visualize the results

Finally you can visualize the results in the _metadata/* folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment