Instapy: Feature: (implemented) MAX LIKE/FOLLOW per HOUR/DAY (works for multiple running also).

Created on 22 Oct 2017  路  14Comments  路  Source: timgrossmann/InstaPy

If it is an interest to someone I will add the code here.

  • I used pickle.
  • Able to read it at any time since it saved as file.
  • wait for next hour/day to return to work if max is reached.

Sion.

Feature discussion enhancement

All 14 comments

@sionking I was wondering about how to set the bot to follow 400 accounts and like 400 posts in 10 hours (I am only aiming to use the bot 10 hours a day to get around Instagram algorithms).

I think that your code might be of some help, so can you please post it, and a bit of guidance on what each line does as I am a beginner?

Thanks

Sure ASAP

@sionking Patiently waiting as I need it really badly :laughing:

I'm interested! 馃檪

It is not bug free (currently I ignore any errors) since I have no much time for it, But it do works.
I started it since the automation crashed all the time so I was unable to track to total daily likes/follows.
Now it will read the file before every run so it wont start liking from the begginging.

  • If the Max is reached I print to console.
  • If the Max is reached I wait certain amount of time (instead of doing diff to next hour) since statisticly it will be the same.
  • every follow/like it will update the file (not best performance but reliablty)

I am attaching the instapy.py file, But I will explain everything here.
Python is a hobby lang since I use c at work in real time codding, so please fix bugs.

Code(instapy.py):
Added new class:

class InstaPyStorage(object):
    TOTAL_START_DAY = '16/10/2017'
    MAX_PER_DAY = 2000
    MAX_PER_HOUR = 90
    def __init__(self):
        self.total = 0
        self.thisDayTotal = 0
        self.thisHourTotal = 0
        self.lastDayExecuted = _datetime.date.today()
        self.lastHourExecuted = _datetime.datetime.now().hour
    def updateStatistics(self):
        # read today's date in 2008-11-22 format, and now time
        today = _datetime.date.today()
        now = _datetime.datetime.now()
        self.total += 1
        if self.lastDayExecuted == today:
            self.thisDayTotal += 1
            if self.lastHourExecuted == now.hour:
                self.thisHourTotal += 1
            else:
                self.lastHourExecuted = now.hour
                self.thisHourTotal = 1
        else:
            self.lastDayExecuted = today
            self.lastHourExecuted == now.hour
            self.thisHourTotal = 1
            self.thisDayTotal = 1

        if self.thisDayTotal >= self.MAX_PER_DAY:
            print('reached MAX_PER_DAY')
            sleep(3600)

        if self.thisHourTotal >= self.MAX_PER_HOUR:
            print('reached MAX_PER_HOUR')
            sleep(600)

adding new def for instapyclass:

def save_do_like_statistics(self):
        # read today's date in 2008-11-22 format, and now time
        try:
            with open('./logs/likesLimitLogFile.pkl', 'rb') as input:
                likes = pickle.load(input)
        except:
            likes = InstaPyStorage()
        # update
        likes.updateStatistics()
        # save after updates
        with open('./logs/likesLimitLogFile.pkl', 'wb') as output:
            pickle.dump(likes, output, pickle.HIGHEST_PROTOCOL)

def save_do_follow_statistics(self):
    """run date information to not exceed the daily/hourly limits"""
    # read today's date in 2008-11-22 format, and now time
    try:
        with open('./logs/followsLimitLogFile.pkl', 'rb') as input:
            follows = pickle.load(input)
    except:
        follows = InstaPyStorage()
    # update
    follows.updateStatistics()
    # save after updates
    with open('./logs/followsLimitLogFile.pkl', 'wb') as output:
        pickle.dump(follows, output, pickle.HIGHEST_PROTOCOL)

def read_likes_statistics(self):
    with open('./logs/likesLimitLogFile.pkl', 'rb') as input:
        likes = pickle.load(input)
    print('--\ntotal Likes',likes.total, 'from date:', likes.TOTAL_START_DAY)
    print('this Day Total Likes:', likes.thisDayTotal)
    print('this Hour Total Likes:', likes.thisHourTotal)
    print('Day Executed last Likes:', likes.lastDayExecuted)
    print('Hour Executed last Likes:', likes.lastHourExecuted)

def read_follows_statistics(self):
    with open('./logs/followsLimitLogFile.pkl', 'rb') as input:
        follows = pickle.load(input)
    print('--\ntotal follows', follows.total, 'from date:', follows.TOTAL_START_DAY)
    print('this Day Total follows:', follows.thisDayTotal)
    print('this Hour Total follows:', follows.thisHourTotal)
    print('Day Executed last follow:', follows.lastDayExecuted)
    print('Hour Executed last follow:', follows.lastHourExecuted)`

Every "liked_img += 1" I added self.save_do_like_statistics():

                        if liked:
                            liked_img += 1
                            self.save_do_like_statistics()

same for follow:

                                followed += follow_user(self.browser, self.follow_restrict, self.username, user_name)
                                self.save_do_follow_statistics()

To read the current state I created new file with the follow:
session = InstaPy(username=insta_username, password=insta_password, selenium_local_session=False) session.read_likes_statistics() session.read_follows_statistics() session.end()

I will attached the file tommorow

@sionking Would be awesome to get a PR for that feature 馃槈

@sionking Thanks for providing this code, but can you provide an example of how to run it as I am new to programming and struggling to understand which commands I need to use.

I just need commands for liking 400 posts and following 400 accounts in 10 hours. I then need a command for the next day for following the accounts. Any help will be much appreciated, Thank you.

timgrossmann PR ? document ?
VKT16 please change the class static:
MAX_PER_DAY = 400
MAX_PER_HOUR = 40

It will not do more than 400 likes per day.
It will not do more than 400 follows per day.

Payattantion if the follow and like percentage are diffrent than it will stop the automation for the first MAX reached like/follow.

If you need auto start every day at specific time use the windows task schduler, read on it in google.

@sionking No, sorry.
A PR is a pull request. An implemented feature that will be merged into the InstaPy codebase.

Thank you for this feature,
I'm trying to implement it into my digital ocean Linux server.

Q: Do I need to install pickel?
Q: Do I just replace the files on my server with the ones in the zip you provided?
Q: after adding these new files do I just reference the MAX_PER_HOUR & MAX_PER_DAY within my .py file?

Q: since I'm using crontab for scheduling, how many times should the script run per day?

Thank you,
kyle.

yes,
yes but pay attenation main branch is updated,
yes,
I run it only once with amount of 500 per tag and in a while loop, so it never stops.
but you can ran 3 diffrent scripts simultanisly, the limit is writen in a file .... thay all be counting to limit toghter.

Sorry to ask, but is this feature implemented yet? if so, why isnt a word about it on the readme file? and also, if so, how do you select those settings?
in which case:
if we where to add this feature to quickstart.py, would it look like this?:
`
from instapy import InstaPy

insta_username = ''
insta_password = ''

set headless_browser=True if you want to run InstaPy on a server

try:
# set these if you're locating the library in the /usr/lib/pythonX.X/ directory
# Settings.database_location = '/path/to/instapy.db'
# Settings.browser_location = '/path/to/chromedriver'

session = InstaPy(username=insta_username,
                  password=insta_password,
                  headless_browser=False,
                  multi_logs=True)
session.login()

# settings
MAX_PER_DAY = 400
MAX_PER_HOUR = 40
session.set_upper_follower_count(limit=2500)
session.set_do_comment(True, percentage=10)
session.set_comments(['aMEIzing!', 'So much fun!!', 'Nicey!'])
session.set_dont_include(['friend1', 'friend2', 'friend3'])
session.set_dont_like(['pizza', 'girl'])

# actions
session.like_by_tags(['natgeo'], amount=1)

finally:
# end the bot session
session.end()
`
Ive been several days trying to find a way to do this so thank you in advance for the help and the contribution

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seuraltimez picture seuraltimez  路  3Comments

Spyd3r0us picture Spyd3r0us  路  3Comments

deronsizemore picture deronsizemore  路  3Comments

n0sw34r picture n0sw34r  路  3Comments

harrypython picture harrypython  路  3Comments