Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save charitra1022/59e719df49378557fd3001b4e5585156 to your computer and use it in GitHub Desktop.

Select an option

Save charitra1022/59e719df49378557fd3001b4e5585156 to your computer and use it in GitHub Desktop.
Python code to check which people you follow doesn't follow you back.
from instaloader import *
# where to store the fetched data
file_path = "/storage/emulated/0/"
# add username and password for any instagram account
user = r''
pwd = r''
L = Instaloader()
L.login(user, pwd)
while True:
username = input("\nEnter Name to Check (Press Enter to exit):")
if not username: break
try:
profiles = TopSearchResults(L.context, username).get_profiles()
i = 1
profile_list = []
print('\nSearch Results for "{}":'.format(username))
for profile in profiles:
print('{}\t{}'.format(i, profile.username))
i+=1
profile_list.append(profile)
print('\nPress Enter to skip')
choice = input('\nEnter the profile number:')
if not choice: continue
profile = profile_list[int(choice)-1]
except exceptions.ProfileNotExistsException:
print('\n"{}" Profile Not Found!\n\n'.format(username))
else:
result_msg = []
result_msg.append('username- {}'.format(profile.username))
followers = []
followees = []
for follower in profile.get_followers():
followers.append(follower.username)
for followee in profile.get_followees():
followees.append(followee.username)
result_msg.append('followers- {}'.format(len(followers)))
result_msg.append('followees- {}'.format(len(followees)))
result_msg.append('\n')
followees_not_follow = []
for followee in followees:
if followee not in followers:
followees_not_follow.append(followee)
result_msg.append('followees_not_follow- {}'.format(len(followees_not_follow)))
result_msg.append('\n')
for i in followees_not_follow: result_msg.append(i)
result_msg = '\n'.join(result_msg)
print()
print(result_msg)
file_path = file_path + "{}.txt".format(profile.username)
with open(file_path, "w") as f:
f.write(result_msg)
print(f'\nText file generated at:\n {file_path}\n')
print('\n==============DONE================\n\n')
L.context.close()
L.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment