I'm getting a list of who a user's following in Instagram using Instapy. How do I create parameters so i only get users who have followers between 5k-10k alongside the grab_following function?
with smart_run(session):
count = 1
sessionCount = random.randint(accountsPerSessionMin, accountsPerSessionMax)
print('======main.py====== Reading ' + str(sessionCount) + ' accounts')
followersList.reverse()
print('ji')
for friend in followersList:
followers = session.grab_following(
username=friend, amount="full", live_match=True, store_locally=True)
print(followers.get_relationship_counts())
if (len(followers) > 0):
# Write result
with open('data/' + user + '-res/' + friend + '.txt', 'w') as outFile:
outFile.write(json.dumps(followers))
# Write to previously checked accounts
alreadyDone.append(friend)
with open('data/already-done.txt', 'w') as outFile:
outFile.write(json.dumps(alreadyDone))
count += 1
print('======main.py====== Read account #' + str(count))
if len(followers) > 0:
print('======main.py====== Found ' +
str(len(followers)) + ' users')
if count % sessionCount == 0:
print('======main.py====== Finished!')
exit(0)
if count % 2 == 0:
time.sleep(random.randint(6, 24))
session.browser.get('https://instagram.com')
time.sleep(random.randint(8, 12))
for i in range(random.randint(1, 3)):
session.browser.execute_script(
'window.scrollTo(0, document.body.scrollHeight)')
time.sleep(random.randint(15, 45))