Skip to content

Commit

Permalink
• Fix crash when trying to get your profile info
Browse files Browse the repository at this point in the history
• Fix crash in storage when username wasn't obtained #80
• Add delays before updating interaction rect and before following a user
  • Loading branch information
Alexander Mishchenko committed Sep 8, 2020
1 parent 9d468df commit 3ff2391
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/action_get_my_profile_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

def get_my_profile_info(device):
navigate(device, Tabs.PROFILE)
random_sleep()
update_interaction_rect(device)

username = None
Expand All @@ -32,9 +33,9 @@ def get_my_profile_info(device):

report_string = ""
if username:
report_string += "Hello, @" + username + "!"
report_string += "Hello, @" + username + "! "
if followers is not None:
report_string += " You have " + str(followers) + " followers"
report_string += "You have " + str(followers) + " followers"
if following is not None:
report_string += " and " + str(following) + " followings"
report_string += " so far."
Expand Down
2 changes: 2 additions & 0 deletions src/action_handle_blogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ def _follow(device, username, follow_percentage):
if coordinator_layout.exists():
coordinator_layout.scroll(DeviceFacade.Direction.TOP)

random_sleep()

profile_actions = device.find(resourceId='com.instagram.android:id/profile_header_actions_top_row',
className='android.widget.LinearLayout')
follow_button = profile_actions.child(index=0)
Expand Down
10 changes: 6 additions & 4 deletions src/interaction_rect_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
def update_interaction_rect(device):
action_bar = device.find(resourceId='com.instagram.android:id/action_bar_container',
className='android.widget.FrameLayout')
global _action_bar_bottom
_action_bar_bottom = action_bar.get_bounds()['bottom']
if action_bar.exists():
global _action_bar_bottom
_action_bar_bottom = action_bar.get_bounds()['bottom']

tab_bar = device.find(resourceId='com.instagram.android:id/tab_bar',
className='android.widget.LinearLayout')
global _tab_bar_top
_tab_bar_top = tab_bar.get_bounds()['top']
if tab_bar.exists():
global _tab_bar_top
_tab_bar_top = tab_bar.get_bounds()['top']


def is_in_interaction_rect(view):
Expand Down
17 changes: 12 additions & 5 deletions src/storage.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
import os
from datetime import datetime, timedelta
from datetime import timedelta
from enum import Enum, unique

from src.utils import *

FILENAME_INTERACTED_USERS = "interacted_users.json"
USER_LAST_INTERACTION = "last_interaction"
USER_FOLLOWING_STATUS = "following_status"
Expand All @@ -11,11 +12,16 @@


class Storage:
interacted_users_path = ""
interacted_users_path = None
interacted_users = {}
whitelist = []

def __init__(self, my_username):
if my_username is None:
print(COLOR_FAIL + "No username, thus the script won't get access to interacted users and sessions data" +
COLOR_ENDC)
return

if not os.path.exists(my_username):
os.makedirs(my_username)
self.interacted_users_path = my_username + "/" + FILENAME_INTERACTED_USERS
Expand Down Expand Up @@ -60,8 +66,9 @@ def is_user_in_whitelist(self, username):
return username in self.whitelist

def _update_file(self):
with open(self.interacted_users_path, 'w') as outfile:
json.dump(self.interacted_users, outfile, indent=4, sort_keys=False)
if self.interacted_users_path is not None:
with open(self.interacted_users_path, 'w') as outfile:
json.dump(self.interacted_users, outfile, indent=4, sort_keys=False)


@unique
Expand Down

0 comments on commit 3ff2391

Please sign in to comment.