Skip to content

Instantly share code, notes, and snippets.

@Suleman-Elahi
Last active September 10, 2020 10:24
Show Gist options
  • Save Suleman-Elahi/e1d7843e4fc809866d5331ee7a628e94 to your computer and use it in GitHub Desktop.
Save Suleman-Elahi/e1d7843e4fc809866d5331ee7a628e94 to your computer and use it in GitHub Desktop.
Auto follow Instagram accounts from a list. The list can be a single column CSV file (without header) or a plain text file with usernames to follow in each line. The script follows 12 accounts in less than a minute. But that can customized by adjusting the sleep parameters at line 18 and 24.
from instagram_private_api import Client, ClientCompatPatch
import time
user_name = 'xxxxxxx'
password = 'xxxxxxx'
api = Client(user_name, password)
f = open("followers.csv", "r").read().split("\n")
i = 0
for x in f:
if bool(x):
try:
user_info = api.username_info(x)
except Exception as e:
print(f"User: {x} ",e)
continue
time.sleep(1)
api.friendships_create(user_info['user']['pk'])
print ("Followed user:: "+x)
i=i+1
if i % 12 == 0:
print("sleeping for 40 sec, total followed till now: ", i)
time.sleep(40)
@Suleman-Elahi
Copy link
Author

It relies on Instagram private API by ping: https://github.com/ping/instagram_private_api

Install the API first via pip in the same way instructions are given on the API repository.

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