Instapy: [Enhancement] Random Sleep Delays Between Each Like/Follow/Unfollow (Salty Sandman V1)

Created on 29 Sep 2018  ·  6Comments  ·  Source: timgrossmann/InstaPy

Hello all, here are my settings for running Instapy 24/7 with approximately 1400 follows/day - 1400 unfollows/day running follow until reaches 7500 and than switch to unfollow until reaches 0.

Open /home/linux/InstaPy-master/instapy.py
Add this code at line 21

from time import sleep
from random import randint

Like Random Sleep Delay - Add this code at line 1239 ( Should look like this.. )

                        #try to like
                        liked = like_image(self.browser,
                                           user_name,
                                           self.blacklist,
                                           self.logger,
                                           self.logfolder)
                        print("sleeping for like 1-2 seconds.")
                        time.sleep(random.randint(1, 2))
                        print("Done sleeping for like oof.")

Follow Random Sleep Delay - Add this code for line 1234 ( Should look like this.. )

                            # following
                            if (self.do_follow and
                                user_name not in self.dont_include and
                                checked_img and
                                following and
                                not follow_restriction("read", user_name,
                                 self.follow_times, self.logger)):
                                print("sleeping for follow 45-50 seconds.")
                                time.sleep(random.randint(45, 50))
                                print("Done sleeping for follow oof.")

Open /home/linux/InstaPy-master/unfollow_util.py
Add this code at line 9

import time 
from time import sleep
from random import randint

Unfollow Random Sleep Delay - Add this code to line 302 ( Should look like this.. )

                            delete_line_from_file('{0}{1}_followedPool.csv'.format(logfolder, username), person +
                                              ",\n", logger)

                            print('')
                            #sleep(15)
                            print("sleeping for unfollow 55-65 seconds.")
                            time.sleep(random.randint(55, 65))
                            print("Done sleeping for like oof.")

Optional : add some japanese and color :)

print("n033[42m ===> 好きに寝る <===033[00m")
time.sleep(random.randint(1, 2))
print("n033[41m ===> 好きなように寝る <===033[00m")

My quickstart.py settings

try:
    session.login()
    # settings
    #session.set_relationship_bounds(enabled=True, delimit_by_numbers=False, max_followers=12000, max_following=4500, min_followers=35, min_following=35)
    #session.set_user_interact(amount=2, randomize=True, percentage=100, media='Photo')
    session.set_do_follow(enabled=True, percentage=100)
    session.set_do_like(enabled=True, percentage=100)
    #session.set_comments(["Cool", "Super!"])
    #session.set_do_comment(enabled=False, percentage=80)
    #session.interact_user_followers(['user1', 'user2', 'user3'], amount=8000, randomize=True)
    #session.set_user_interact(amount=2, randomize=True, percentage=100, media='Photo')
    #session.follow_user_followers(['user1', 'user2', 'user3'], amount=8000, randomize=False, interact=True)
    #session.unfollow_users(amount=7500, nonFollowers=True, style="RANDOM", unfollow_after=42*60*60, sleep_delay=3)
    # actions
    session.like_by_tags(['맛있는'], amount=8000)
enhancement

Most helpful comment

This is what I did:

            # check if we need to sleep before liking
            if sleep_diff(TimesLog.last_follow_time, Limits.min_time_between_follows):
                # find the element once again (avoid StaleElementReferenceException )
                #follow_button = browser.find_element_by_xpath(follow_xpath)
                pass # need to check if we get error StaleElementReferenceException or not.
            TimesLog.last_follow_time = datetime.now()
class TimesLog:
    last_likes_time = None
    last_follow_time = None
    last_unfollow_time = None
    last_comments_time = None
def sleep_diff(last, min_time_between):
    # check time pass from last like is Sufficient
    now = datetime.now()
    time_diff_last_like = now - last
    if time_diff_last_like < timedelta(seconds=min_time_between):
        sleep(min_time_between - time_diff_last_like.seconds)
        return True
    else:
        return False
class TimesLog:
    last_likes_time = None
    last_follow_time = None
    last_unfollow_time = None
    last_comments_time = None



md5-4ae739fdfdc65f4a688a55e786a0664f



class Limits:
    min_time_between_likes = 30
    min_time_between_follows = 60
    min_time_between_unfollow = 30
    min_time_between_comments = 30



md5-958735c2657defd797e7ad562fe2cdf9



        TimesLog.last_likes_time = now - timedelta(seconds=Limits.min_time_between_likes)
        TimesLog.last_follow_time = now - timedelta(seconds=Limits.min_time_between_follows)
        TimesLog.last_unfollow_time = now - timedelta(seconds=Limits.min_time_between_unfollow)
        TimesLog.last_comment_time = now - timedelta(seconds=Limits.min_time_between_comments)

I need to PR this soon.

All 6 comments

Thanks, but sleep should be with a referral to last action..

@sionking i agree, but this works for noobs who just want maximum interacting with no strategy.

@timgrossmann suggested maybe make file called set_action_delays which will refer to last action so random custom sleep can be used with comment, interact, follow_users_followers, etc... this only works for session.unfollow_users / session.like_by_tags but its just concept for further development.

This is what I did:

            # check if we need to sleep before liking
            if sleep_diff(TimesLog.last_follow_time, Limits.min_time_between_follows):
                # find the element once again (avoid StaleElementReferenceException )
                #follow_button = browser.find_element_by_xpath(follow_xpath)
                pass # need to check if we get error StaleElementReferenceException or not.
            TimesLog.last_follow_time = datetime.now()
class TimesLog:
    last_likes_time = None
    last_follow_time = None
    last_unfollow_time = None
    last_comments_time = None
def sleep_diff(last, min_time_between):
    # check time pass from last like is Sufficient
    now = datetime.now()
    time_diff_last_like = now - last
    if time_diff_last_like < timedelta(seconds=min_time_between):
        sleep(min_time_between - time_diff_last_like.seconds)
        return True
    else:
        return False
class TimesLog:
    last_likes_time = None
    last_follow_time = None
    last_unfollow_time = None
    last_comments_time = None



md5-4ae739fdfdc65f4a688a55e786a0664f



class Limits:
    min_time_between_likes = 30
    min_time_between_follows = 60
    min_time_between_unfollow = 30
    min_time_between_comments = 30



md5-958735c2657defd797e7ad562fe2cdf9



        TimesLog.last_likes_time = now - timedelta(seconds=Limits.min_time_between_likes)
        TimesLog.last_follow_time = now - timedelta(seconds=Limits.min_time_between_follows)
        TimesLog.last_unfollow_time = now - timedelta(seconds=Limits.min_time_between_unfollow)
        TimesLog.last_comment_time = now - timedelta(seconds=Limits.min_time_between_comments)

I need to PR this soon.

@sionking my question is why does it have to be so complicated why not just put

                    print("sleeping for unfollow 55-65 seconds.")
                    time.sleep(random.randint(55, 65))
                    print("Done sleeping for like oof.")

this will not get you blocked, it is random to deter automation detection, also understandable for novice python programmers. why not just put this code after each function and not over-complicate it ?

Can I still implement these enhancements? cos it looks like it's been already implemented.

@sionking my question is why does it have to be so complicated why not just put

                    print("sleeping for unfollow 55-65 seconds.")
                    time.sleep(random.randint(55, 65))
                    print("Done sleeping for like oof.")

this will not get you blocked, it is random to deter automation detection, also understandable for novice python programmers. why not just put this code after each function and not over-complicate it ?

I will give you an example:

  1. 0 sec time like
  2. 30 sec time want to like again
  3. wait ~60 sec
  4. 90 sec another like

time diff is not controlled you got 90 sec and not 60.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thisishotdog picture thisishotdog  ·  3Comments

deronsizemore picture deronsizemore  ·  3Comments

neomh picture neomh  ·  3Comments

ghost picture ghost  ·  3Comments

wyvers picture wyvers  ·  3Comments