Skip to content

Commit

Permalink
Count only successful interactions in --interactions-count; set 70 by…
Browse files Browse the repository at this point in the history
… default
  • Loading branch information
Alexander Mishchenko committed Jul 9, 2020
1 parent b454293 commit 23e6c92
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
14 changes: 8 additions & 6 deletions insomniac.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,10 @@ def _parse_arguments():
metavar='300',
default=1000)
parser.add_argument('--interactions-count',
help='number of interactions per each blogger, 100 by default',
metavar='100',
default=100)
help='number of interactions per each blogger, 70 by default. Only successful interactions'
' count',
metavar='70',
default=70)
parser.add_argument('--repeat',
help='repeat the same session again after N minutes after completion, disabled by default',
metavar='180')
Expand Down Expand Up @@ -278,7 +279,7 @@ def _on_like():
session_state.totalLikes += 1


def _on_interaction(blogger, succeed, followed, count, interactions_limit, likes_limit, on_likes_limit_reached):
def _on_interaction(blogger, succeed, followed, interactions_limit, likes_limit, on_likes_limit_reached):
session_state = sessions[-1]
session_state.add_interaction(blogger, succeed, followed)

Expand All @@ -289,8 +290,9 @@ def _on_interaction(blogger, succeed, followed, count, interactions_limit, likes
on_likes_limit_reached()
can_continue = False

if count >= interactions_limit:
print("Made " + str(count) + " interactions, finish.")
successful_interactions_count = session_state.get_successful_interactions_count()
if successful_interactions_count >= interactions_limit:
print("Made " + str(successful_interactions_count) + " successful interactions, finish.")
can_continue = False

return can_continue
Expand Down
5 changes: 1 addition & 4 deletions src/action_handle_blogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def is_at_least_one_follower():

def _iterate_over_followers(device, interaction, storage, on_interaction, is_myself):
followers_per_screen = None
interactions_count = 0

def scrolled_to_top():
row_search = device(resourceId='com.instagram.android:id/row_search_edit_text',
Expand Down Expand Up @@ -128,10 +127,8 @@ def scrolled_to_top():
can_follow = not is_myself and storage.get_following_status(username) == FollowingStatus.NONE
interaction_succeed, followed = interaction(device, username=username, can_follow=can_follow)
storage.add_interacted_user(username, followed=followed)
interactions_count += 1
can_continue = on_interaction(succeed=interaction_succeed,
followed=followed,
count=interactions_count)
followed=followed)

if not can_continue:
return
Expand Down
3 changes: 3 additions & 0 deletions src/session_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ def add_interaction(self, blogger, succeed, followed):
if followed:
self.totalFollowed += 1

def get_successful_interactions_count(self):
return sum(self.successfulInteractions.values())

def is_finished(self):
return self.finishTime is not None

0 comments on commit 23e6c92

Please sign in to comment.