Igbot: Unfollow users who haven't posted in a while (or have't posted more than 5 photos)

Created on 29 Sep 2017  Â·  6Comments  Â·  Source: ohld/igbot

Unfollow users who haven't posted in a while (or have't posted more than 5 photos)

Could this feature be implemented?
I would like to at least learn how to create such a script, if possible.

stale

Most helpful comment

@AmruthPillai It's very expensive because bot need get information about every your follower.
You can try this script

import sys
import os
from tqdm import tqdm

sys.path.append(os.path.join(sys.path[0], '../'))
from instabot import Bot
from instabot.bot import delay

def get_unactive_followers(my_bot, followers, min_media_count=5):
    unactive_followers = []
    for follower in tqdm(followers, 'Getting follower info'):
        follower_info = my_bot.get_user_info(follower)
        if follower_info['media_count'] < min_media_count:
            unactive_followers.append(follower)
        delay.small_delay(my_bot)

    return unactive_followers


bot = Bot()
bot.login()

min_media_count = 5

followers = bot.get_user_followers(bot.user_id)
unactive_followers = get_unactive_followers(bot, followers, min_media_count)

bot.unfollow_users(unactive_followers)

All 6 comments

@AmruthPillai It's very expensive because bot need get information about every your follower.
You can try this script

import sys
import os
from tqdm import tqdm

sys.path.append(os.path.join(sys.path[0], '../'))
from instabot import Bot
from instabot.bot import delay

def get_unactive_followers(my_bot, followers, min_media_count=5):
    unactive_followers = []
    for follower in tqdm(followers, 'Getting follower info'):
        follower_info = my_bot.get_user_info(follower)
        if follower_info['media_count'] < min_media_count:
            unactive_followers.append(follower)
        delay.small_delay(my_bot)

    return unactive_followers


bot = Bot()
bot.login()

min_media_count = 5

followers = bot.get_user_followers(bot.user_id)
unactive_followers = get_unactive_followers(bot, followers, min_media_count)

bot.unfollow_users(unactive_followers)

The script is brilliant, just what I asked for... but you're right, it is taxing on the server. It throws an error saying too many requests right when it's gathering information about followers.

Getting follower info:   5%|â–Š              | 100/1888 [05:44<1:47:34,  3.61s/it]2017-10-01 23:02:45,870 - WARNING - Request return 429 error!
2017-10-01 23:02:45,871 - WARNING - That means 'too many requests'. I'll go to sleep for 5 minutes.

Is there a way to break up this process into first 50-100 followers, perform the actions, and after a bigger delay, rerun the process?

i think best way to approach this is to use whitelist-blacklist example.
this way you can have separate, occasional proccess that looks up users and another that unfollows based on the blacklist/whitelist generated.

@pxtyr Can you give an example?

Basic workflow might be:

fetch and list userids of who you are following (stored in followed.txt)
list [:n] (say 100 at a time per run of script)
run the get.user.info sequence that is used for existing auto-follow script
if fail get.user.info (ie. If media count < 5), add userid to file like unfollow.txt

You can run this script every hour or so.. basically auditing 100 users at a time... this will make it easier not to be banned.

Then on separate occasion you can run simple unfollow script that simply looks at the unfollow.txt

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tayfunyasar picture tayfunyasar  Â·  7Comments

ohld picture ohld  Â·  8Comments

iMoein picture iMoein  Â·  5Comments

balochlens picture balochlens  Â·  5Comments

md4956 picture md4956  Â·  4Comments