{"action":"created","issue":{"url":"https://api.github.com/repos/timgrossmann/InstaPy/issues/797","repository_url":"https://api.github.com/repos/timgrossmann/InstaPy","labels_url":"https://api.github.com/repos/timgrossmann/InstaPy/issues/797/labels{/name}","comments_url":"https://api.github.com/repos/timgrossmann/InstaPy/issues/797/comments","events_url":"https://api.github.com/repos/timgrossmann/InstaPy/issues/797/events","html_url":"https://github.com/timgrossmann/InstaPy/issues/797","id":267458412,"number":797,"title":"Feature: (implemented) MAX LIKE/FOLLOW per HOUR/DAY (works for multiple running also).","user":{"login":"sionking","id":7851877,"avatar_url":"https://avatars2.githubusercontent.com/u/7851877?v=4","gravatar_id":"","url":"https://api.github.com/users/sionking","html_url":"https://github.com/sionking","followers_url":"https://api.github.com/users/sionking/followers","following_url":"https://api.github.com/users/sionking/following{/other_user}","gists_url":"https://api.github.com/users/sionking/gists{/gist_id}","starred_url":"https://api.github.com/users/sionking/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sionking/subscriptions","organizations_url":"https://api.github.com/users/sionking/orgs","repos_url":"https://api.github.com/users/sionking/repos","events_url":"https://api.github.com/users/sionking/events{/privacy}","received_events_url":"https://api.github.com/users/sionking/received_events","type":"User","site_admin":false},"labels":[{"id":588593364,"url":"https://api.github.com/repos/timgrossmann/InstaPy/labels/discussion","name":"discussion","color":"5319e7","default":false},{"id":450146659,"url":"https://api.github.com/repos/timgrossmann/InstaPy/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":539195330,"url":"https://api.github.com/repos/timgrossmann/InstaPy/labels/Feature","name":"Feature","color":"b60205","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-10-22T11:50:33Z","updated_at":"2017-10-22T18:58:26Z","closed_at":"2017-10-22T18:58:26Z","author_association":"NONE","body":"If it is an interest to someone I will add the code here.\r\n\r\n* I used pickle.\r\n* Able to read it at any time since it saved as file.\r\n* wait for next hour/day to return to work if max is reached.\r\n\r\nSion."},"comment":{"url":"https://api.github.com/repos/timgrossmann/InstaPy/issues/comments/338500550","html_url":"https://github.com/timgrossmann/InstaPy/issues/797#issuecomment-338500550","issue_url":"https://api.github.com/repos/timgrossmann/InstaPy/issues/797","id":338500550,"user":{"login":"sionking","id":7851877,"avatar_url":"https://avatars2.githubusercontent.com/u/7851877?v=4","gravatar_id":"","url":"https://api.github.com/users/sionking","html_url":"https://github.com/sionking","followers_url":"https://api.github.com/users/sionking/followers","following_url":"https://api.github.com/users/sionking/following{/other_user}","gists_url":"https://api.github.com/users/sionking/gists{/gist_id}","starred_url":"https://api.github.com/users/sionking/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sionking/subscriptions","organizations_url":"https://api.github.com/users/sionking/orgs","repos_url":"https://api.github.com/users/sionking/repos","events_url":"https://api.github.com/users/sionking/events{/privacy}","received_events_url":"https://api.github.com/users/sionking/received_events","type":"User","site_admin":false},"created_at":"2017-10-22T18:58:26Z","updated_at":"2017-10-22T18:58:26Z","author_association":"NONE","body":"It is not bug free (currently I ignore any errors) since I have no much time for it, But it do works.\r\nI started it since the automation crashed all the time so I was unable to track to total daily likes/follows.\r\nNow it will read the file before every run so it wont start liking from the begginging.\r\n- If the Max is reached I print to console.\r\n- 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.\r\n- every follow/like it will update the file (not best performance but reliablty)\r\n\r\nI am attaching the instapy.py file, But I will explain everything here.\r\nPython is a hobby lang since I use c at work in real time codding, so please fix bugs.\r\n\r\nCode(instapy.py):\r\nAdded new class:\r\n```\r\n\r\nclass InstaPyStorage(object):\r\n    TOTAL_START_DAY = '16/10/2017'\r\n    MAX_PER_DAY = 2000\r\n    MAX_PER_HOUR = 90\r\n    def __init__(self):\r\n        self.total = 0\r\n        self.thisDayTotal = 0\r\n        self.thisHourTotal = 0\r\n        self.lastDayExecuted = _datetime.date.today()\r\n        self.lastHourExecuted = _datetime.datetime.now().hour\r\n    def updateStatistics(self):\r\n        # read today's date in 2008-11-22 format, and now time\r\n        today = _datetime.date.today()\r\n        now = _datetime.datetime.now()\r\n        self.total += 1\r\n        if self.lastDayExecuted == today:\r\n            self.thisDayTotal += 1\r\n            if self.lastHourExecuted == now.hour:\r\n                self.thisHourTotal += 1\r\n            else:\r\n                self.lastHourExecuted = now.hour\r\n                self.thisHourTotal = 1\r\n        else:\r\n            self.lastDayExecuted = today\r\n            self.lastHourExecuted == now.hour\r\n            self.thisHourTotal = 1\r\n            self.thisDayTotal = 1\r\n\r\n        if self.thisDayTotal >= self.MAX_PER_DAY:\r\n            print('reached MAX_PER_DAY')\r\n            sleep(3600)\r\n\r\n        if self.thisHourTotal >= self.MAX_PER_HOUR:\r\n            print('reached MAX_PER_HOUR')\r\n            sleep(600)\r\n\r\n```\r\n\r\nadding new def for instapyclass:\r\n`    def save_do_like_statistics(self):\r\n        \"\"\"run date information to not exceed the daily/hourly limits\"\"\"\r\n        # read today's date in 2008-11-22 format, and now time\r\n        try:\r\n            with open('./logs/likesLimitLogFile.pkl', 'rb') as input:\r\n                likes = pickle.load(input)\r\n        except:\r\n            likes = InstaPyStorage()\r\n        # update\r\n        likes.updateStatistics()\r\n        # save after updates\r\n        with open('./logs/likesLimitLogFile.pkl', 'wb') as output:\r\n            pickle.dump(likes, output, pickle.HIGHEST_PROTOCOL)\r\n\r\n    def save_do_follow_statistics(self):\r\n        \"\"\"run date information to not exceed the daily/hourly limits\"\"\"\r\n        # read today's date in 2008-11-22 format, and now time\r\n        try:\r\n            with open('./logs/followsLimitLogFile.pkl', 'rb') as input:\r\n                follows = pickle.load(input)\r\n        except:\r\n            follows = InstaPyStorage()\r\n        # update\r\n        follows.updateStatistics()\r\n        # save after updates\r\n        with open('./logs/followsLimitLogFile.pkl', 'wb') as output:\r\n            pickle.dump(follows, output, pickle.HIGHEST_PROTOCOL)\r\n\r\n    def read_likes_statistics(self):\r\n        with open('./logs/likesLimitLogFile.pkl', 'rb') as input:\r\n            likes = pickle.load(input)\r\n        print('--\\ntotal Likes',likes.total, 'from date:', likes.TOTAL_START_DAY)\r\n        print('this Day Total Likes:', likes.thisDayTotal)\r\n        print('this Hour Total Likes:', likes.thisHourTotal)\r\n        print('Day Executed last Likes:', likes.lastDayExecuted)\r\n        print('Hour Executed last Likes:', likes.lastHourExecuted)\r\n\r\n    def read_follows_statistics(self):\r\n        with open('./logs/followsLimitLogFile.pkl', 'rb') as input:\r\n            follows = pickle.load(input)\r\n        print('--\\ntotal follows', follows.total, 'from date:', follows.TOTAL_START_DAY)\r\n        print('this Day Total follows:', follows.thisDayTotal)\r\n        print('this Hour Total follows:', follows.thisHourTotal)\r\n        print('Day Executed last follow:', follows.lastDayExecuted)\r\n        print('Hour Executed last follow:', follows.lastHourExecuted)`\r\n\r\nTo read the current state:\r\n`session = InstaPy(username=insta_username, password=insta_password, selenium_local_session=False)\r\nsession.read_likes_statistics()\r\nsession.read_follows_statistics()\r\nsession.end()`\r\n"}}
{"actor":{"display_login":"sionking"}}