Skip to content

Commit

Permalink
Merge pull request #168 from GramAddict/develop
Browse files Browse the repository at this point in the history
Hotfix Release v1.2.3
  • Loading branch information
philip-ulrich authored Jan 1, 2021
2 parents 75f25ad + 7e14d73 commit e84fdee
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ whitelist.txt
Pipfile
Pipfile.lock
*.pdf
*.mp4
*.log*
!config-examples/*
10 changes: 3 additions & 7 deletions GramAddict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,8 @@ def run():

logger.info("Device screen on and unlocked.")

open_instagram()
if configs.args.screen_record:
logger.warning(
"Start screen recording: it will be saved as debug.mp4 in main folder"
)
device.screenrecord()
open_instagram(device, configs.args.screen_record)

try:
profileView = TabBarView(device).navigateToProfile()
random_sleep()
Expand Down Expand Up @@ -187,7 +183,7 @@ def run():
)
break

close_instagram()
close_instagram(device, configs.args.screen_record)
session_state.finishTime = datetime.now()

if configs.args.screen_sleep:
Expand Down
10 changes: 5 additions & 5 deletions GramAddict/core/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
logger = logging.getLogger(__name__)


def run_safely(device, device_id, sessions, session_state):
def run_safely(device, device_id, sessions, session_state, screen_record):
def actual_decorator(func):
def wrapper(*args, **kwargs):
session_state = sessions[-1]
Expand Down Expand Up @@ -55,7 +55,7 @@ def wrapper(*args, **kwargs):
)
TabBarView(device).navigateToProfile()
except KeyboardInterrupt:
close_instagram()
close_instagram(device, screen_record)
logger.info(
f"-------- FINISH: {datetime.now().time()} --------",
extra={"color": f"{Style.BRIGHT}{Fore.YELLOW}"},
Expand All @@ -75,9 +75,9 @@ def wrapper(*args, **kwargs):
save_crash(device)
logger.info("No idea what it was. Let's try again.")
# Hack for the case when IGTV was accidentally opened
close_instagram()
close_instagram(device, screen_record)
random_sleep()
open_instagram()
open_instagram(device, screen_record)
TabBarView(device).navigateToProfile()
except LanguageNotEnglishException:
logger.info(
Expand All @@ -87,7 +87,7 @@ def wrapper(*args, **kwargs):
except Exception as e:
logger.error(traceback.format_exc())
save_crash(device)
close_instagram()
close_instagram(device, screen_record)
print_full_report(sessions)
sessions.persist(directory=session_state.my_username)
raise e
Expand Down
30 changes: 28 additions & 2 deletions GramAddict/core/device_facade.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from enum import Enum, auto
from os import popen
from os import popen, listdir, getcwd
from random import uniform
from re import search
from time import sleep
Expand Down Expand Up @@ -80,12 +80,33 @@ def back(self):
else:
self.deviceV2.press("back")

def screenrecord(self, output="debug.mp4", fps=10):
def start_screenrecord(self, output="debug_0000.mp4", fps=10):
"""for debug, available for V2 only"""
if self.deviceV1 is not None:
logger.error("Screen recording is only available for UA2")
else:
mp4_files = [f for f in listdir(getcwd()) if f.endswith(".mp4")]
if mp4_files != []:
last_mp4 = mp4_files[-1]
debug_number = "{0:0=4d}".format(int(last_mp4[-8:-4]) + 1)
output = f"debug_{debug_number}.mp4"
self.deviceV2.screenrecord(output, fps)
logger.warning(
f"Start screen recording: it will be saved as '{output}' in '{getcwd()}'"
)

def stop_screenrecord(self):
"""for debug, available for V2 only"""
if self.deviceV1 is not None:
logger.error("Screen recording is only available for UA2")
else:
if self.deviceV2.screenrecord.stop():
mp4_files = [f for f in listdir(getcwd()) if f.endswith(".mp4")]
if mp4_files != []:
last_mp4 = mp4_files[-1]
logger.warning(
f"Screen recorder has been stoped succesfully! File '{last_mp4}' available in '{getcwd()}'"
)

def screenshot(self, path):
if self.deviceV1 is not None:
Expand Down Expand Up @@ -471,6 +492,10 @@ def click(self, mode=None):
x_offset = uniform(0.6, 0.85)
y_offset = uniform(0.15, 0.85)

elif mode == self.Location.BOTTOMRIGHT:
x_offset = uniform(0.8, 0.9)
y_offset = uniform(0.8, 0.9)

else:
x_offset = 0.5
y_offset = 0.5
Expand Down Expand Up @@ -741,6 +766,7 @@ class Location(Enum):
BOTTOM = auto()
RIGHT = auto()
LEFT = auto()
BOTTOMRIGHT = auto()

class Direction(Enum):
TOP = auto()
Expand Down
8 changes: 6 additions & 2 deletions GramAddict/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def open_instagram_with_url(url):
return True


def open_instagram():
def open_instagram(device, screen_record):
logger.info("Open Instagram app")
cmd = (
"adb"
Expand All @@ -112,15 +112,19 @@ def open_instagram():
if err:
logger.debug(err)
random_sleep()
if screen_record:
device.start_screenrecord()


def close_instagram():
def close_instagram(device, screen_record):
logger.info("Close Instagram app")
os.popen(
"adb"
+ ("" if configs.device_id is None else " -s " + configs.device_id)
+ f" shell am force-stop {app_id}"
).close()
if screen_record:
device.stop_screenrecord()
# close out atx-agent
os.popen(
"adb"
Expand Down
65 changes: 47 additions & 18 deletions GramAddict/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,20 @@ def navigateToUsername(
search_edit_text = self._getSearchEditText()
search_edit_text.click()
random_sleep(1, 2)
tabbar_container = self.device.find(
resourceId=ResourceID.FIXED_TABBAR_TABS_CONTAINER
)
if tabbar_container.exists(True):
delta = tabbar_container.get_bounds()["bottom"]
else:
delta = 375
if swipe_to_accounts:
logger.debug("Close the keyboard")
DeviceFacade.back(self.device)
logger.debug("Swipe up to close the keyboard if present")
UniversalActions(self.device)._swipe_points(
direction=Direction.UP,
start_point_y=randint(delta + 10, delta + 150),
delta_y=randint(50, 100),
)
random_sleep(1, 2)
DeviceFacade.swipe(self.device, DeviceFacade.Direction.LEFT, 0.8)
random_sleep(1, 2)
Expand All @@ -318,8 +329,12 @@ def navigateToUsername(
searched_user_recent.click()
return ProfileView(self.device, is_own_profile=False)
search_edit_text.set_text(username)
logger.debug("Close the keyboard")
DeviceFacade.back(self.device)
logger.debug("Swipe up to close the keyboard if present")
UniversalActions(self.device)._swipe_points(
direction=Direction.UP,
start_point_y=randint(delta + 10, delta + 150),
delta_y=randint(50, 100),
)
random_sleep(1, 2)
username_view = self._getUsernameRow(username)
if not username_view.exists(True):
Expand All @@ -346,8 +361,19 @@ def navigateToHashtag(self, hashtag):
return None
hashtag_tab.click()
random_sleep(1, 2)
logger.debug("Close the keyboard")
DeviceFacade.back(self.device)
tabbar_container = self.device.find(
resourceId=ResourceID.FIXED_TABBAR_TABS_CONTAINER
)
if tabbar_container.exists(True):
delta = tabbar_container.get_bounds()["bottom"]
else:
delta = 375
logger.debug("Swipe up to close the keyboard if present")
UniversalActions(self.device)._swipe_points(
direction=Direction.UP,
start_point_y=randint(delta + 10, delta + 150),
delta_y=randint(50, 100),
)
random_sleep(1, 2)
# check if that hashtag already exists in the recent search list -> act as human
hashtag_view_recent = self._getHashtagRow(hashtag[1:])
Expand Down Expand Up @@ -672,7 +698,10 @@ def navigateToLanguage(self):
def changeToUsername(self, username):
action_bar = self.device.find(resourceId=ResourceID.ACTION_BAR_LARGE_TITLE)
current_profile_name = action_bar.get_text().upper()
if current_profile_name == username.upper():
# in private accounts there is little lock which is codec as two spaces (should be \u1F512)
if current_profile_name == username.upper() or current_profile_name == (
" " + username.upper()
):
logger.info(
f"You are already logged as {username}!",
extra={"color": f"{Style.BRIGHT}{Fore.BLUE}"},
Expand All @@ -687,7 +716,7 @@ def changeToUsername(self, username):
)
if found_obj.exists():
logger.info(
f"Switching to {configs.args.username}...",
f"Switching to {username}...",
extra={"color": f"{Style.BRIGHT}{Fore.BLUE}"},
)
found_obj.click()
Expand Down Expand Up @@ -1089,19 +1118,19 @@ def getProfileBiography(self):
).search(biography_text)
if is_long_bio is not None:
logger.debug('Found "… more" in bio - trying to expand')
# Clicking the biography is dangerous. Clicking "right" is safest so we can try to avoid hashtags
biography.click(biography.Location.RIGHT)
# If we do click a hashtag (VERY possible) - let's back out
# a short bio is better than no bio
try:
return biography.get_text()
except:
username = self.getUsername()
for _ in range(2):
# Clicking the biography is dangerous. Clicking "bottomright" is safest so we can try to avoid hashtags and tags
biography.click(biography.Location.BOTTOMRIGHT)
random_sleep()
if username == self.getUsername():
return biography.get_text()
logger.debug(
"Can't find biography - did we click a hashtag? Go back."
"We're not in the same page - did we click a hashtag or a tag? Go back."
)
logger.info("Failed to expand biography - checking short view.")
self.device.back()
return biography.get_text()
logger.info("Failed to expand biography - checking short view.")
return biography.get_text()
return biography_text
return ""

Expand Down
1 change: 1 addition & 0 deletions GramAddict/plugins/action_unfollow_followers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(self):
device_id=self.device_id,
sessions=self.sessions,
session_state=self.session_state,
screen_record=self.args.screen_record,
)
def job():
self.unfollow(
Expand Down
1 change: 1 addition & 0 deletions GramAddict/plugins/force_interact.dis
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class ForceIteract(Plugin):
device_id=self.device_id,
sessions=self.sessions,
session_state=self.session_state,
screen_record=self.args.screen_record,
)
def job():
self.handle_blogger(
Expand Down
1 change: 1 addition & 0 deletions GramAddict/plugins/interact_blogger_followers.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def __init__(self):
device_id=self.device_id,
sessions=self.sessions,
session_state=self.session_state,
screen_record=self.args.screen_record,
)
def job():
self.handle_blogger(
Expand Down
1 change: 1 addition & 0 deletions GramAddict/plugins/interact_hashtag_likers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def __init__(self):
device_id=self.device_id,
sessions=self.sessions,
session_state=self.session_state,
screen_record=self.args.screen_record,
)
def job():
self.handle_hashtag(
Expand Down
3 changes: 2 additions & 1 deletion GramAddict/plugins/interact_hashtag_posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
seed()


class InteractHashtagLikers(Plugin):
class InteractHashtagPosts(Plugin):
"""Handles the functionality of interacting with a hashtags post owners"""

def __init__(self):
Expand Down Expand Up @@ -134,6 +134,7 @@ def __init__(self):
device_id=self.device_id,
sessions=self.sessions,
session_state=self.session_state,
screen_record=self.args.screen_record,
)
def job():
self.handle_hashtag(
Expand Down
1 change: 1 addition & 0 deletions GramAddict/plugins/interact_usernames.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def __init__(self):
device_id=self.device_id,
sessions=self.sessions,
session_state=self.session_state,
screen_record=self.args.screen_record,
)
def job():
self.handle_username_file(
Expand Down
1 change: 1 addition & 0 deletions GramAddict/plugins/like_from_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(self):
device_id=self.device_id,
sessions=self.sessions,
session_state=self.session_state,
screen_record=self.args.screen_record,
)
def job():
self.process_file(filename, on_like, storage)
Expand Down
2 changes: 1 addition & 1 deletion GramAddict/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.2"
__version__ = "1.2.3"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="gramaddict",
version="1.2.2",
version="1.2.3",
author="GramAddict Team",
author_email="[email protected]",
description="Completely free and open source human-like Instagram bot. Powered by UIAutomator2 and compatible with basically any android device that can run instagram - real or emulated.",
Expand Down

0 comments on commit e84fdee

Please sign in to comment.