Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the language check #363

Merged
merged 7 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ labels: kind/bug


Relevant Logs:

- activate debug mode in confing.yml if you want to paste from the console, otherwise attach the log file from the logs folder



Expand Down
4 changes: 2 additions & 2 deletions GramAddict/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Human-like Instagram bot powered by UIAutomator2"""
__version__ = "3.2.7"
__tested_ig_version__ = "226.1.0.16.117"
__version__ = "3.2.8"
__tested_ig_version__ = "263.2.0.19.104"

from GramAddict.core.bot_flow import start_bot

Expand Down
1 change: 1 addition & 0 deletions GramAddict/core/bot_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def start_bot(**kwargs):
account_view = AccountView(device)
tab_bar_view = TabBarView(device)
try:
account_view.navigate_to_main_account()
check_if_english(device)
if configs.args.username is not None:
success = account_view.changeToUsername(configs.args.username)
Expand Down
30 changes: 4 additions & 26 deletions GramAddict/core/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@

from GramAddict.core.device_facade import Timeout
from GramAddict.core.views import (
AccountView,
HashTagView,
LanguageView,
OptionsView,
PlacesView,
PostsGridView,
ProfileView,
SettingsView,
TabBarView,
UniversalActions,
)
Expand All @@ -21,36 +17,18 @@


def check_if_english(device):
logger.debug("Navigate to PROFILE.")
UniversalActions.close_keyboard(device)
ProfileView(device).click_on_avatar()
if ProfileView(device).getFollowingCount() is None:
ProfileView(device).click_on_avatar()
"""check if app is in English"""
logger.debug("Checking if app is in English..")
post, follower, following = ProfileView(device)._getSomeText()
if None in {post, follower, following}:
logger.warning(
"Failed to check your Instagram language. Be sure to set it to English or the bot won't work!"
)
elif post == "Posts" and follower == "Followers" and following == "Following":
elif post == "posts" and follower == "followers" and following == "following":
logger.debug("Instagram in English.")
else:
logger.info("Switching to English locale.", extra={"color": f"{Fore.GREEN}"})
try:
ProfileView(device).navigateToOptions()
OptionsView(device).navigateToSettings()
SettingsView(device).navigateToAccount()
AccountView(device).navigateToLanguage()
LanguageView(device).setLanguage("english")
logger.debug(
"After changing language, IG goes to feed. Let's go to profile view again."
)
ProfileView(device).click_on_avatar()
except Exception as ex:
logger.error(f"Please change the language manually to English! Error: {ex}")
sys.exit(1)
if ProfileView(device).getFollowingCount() is None:
ProfileView(device).click_on_avatar()
logger.error("Please change the language manually to English!")
sys.exit(1)
return ProfileView(device, is_own_profile=True)


Expand Down
12 changes: 10 additions & 2 deletions GramAddict/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,13 @@ def navigateToLanguage(self):
logger.error("Not able to set your app in English! Do it by yourself!")
exit(0)

def navigate_to_main_account(self):
logger.debug("Navigating to main account...")
profile_view = ProfileView(self.device)
profile_view.click_on_avatar()
if profile_view.getFollowingCount() is None:
profile_view.click_on_avatar()

def changeToUsername(self, username: str):
action_bar = ProfileView._getActionBarTitleBtn(self)
if action_bar is not None:
Expand Down Expand Up @@ -1449,7 +1456,8 @@ def _getActionBarTitleBtn(self, watching_stories=False):
)
return None

def _getSomeText(self):
def _getSomeText(self) -> Tuple[Optional[str], Optional[str], Optional[str]]:
"""Get some text from the profile to check the language"""
obj = self.device.find(
resourceIdMatches=ResourceID.ROW_PROFILE_HEADER_TEXTVIEW_POST_CONTAINER
)
Expand Down Expand Up @@ -1477,7 +1485,7 @@ def _getSomeText(self):
.child(index=1)
.get_text()
)
return post, followers, following
return post.casefold(), followers.casefold(), following.casefold()
except Exception as e:
logger.debug(f"Exception: {e}")
logger.warning(
Expand Down
2 changes: 1 addition & 1 deletion GramAddict/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# that file is deprecated, current version is now stored in GramAddict/__init__.py
__version__ = "3.2.7"
__version__ = "3.2.8"