Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
Update to v3.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Mishchenko committed Apr 2, 2022
1 parent 7bb4c55 commit e50d9e7
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 26 deletions.
2 changes: 1 addition & 1 deletion insomniac/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__title__ = 'insomniac'
__description__ = 'Simple Instagram bot for automated Instagram interaction using Android.'
__url__ = 'https://github.com/alexal1/Insomniac/'
__version__ = '3.8.1'
__version__ = '3.8.2'
__debug_mode__ = False
__author__ = 'Insomniac Team'
__author_email__ = 'info@insomniac-bot.com'
Expand Down
1 change: 1 addition & 0 deletions insomniac/actions_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
StoryWatchAction = namedtuple('StoryWatchAction', 'source_name source_type user')
CommentAction = namedtuple('CommentAction', 'source_name source_type user comment')
DirectMessageAction = namedtuple('DirectMessageAction', 'user message')
DirectMessageBackdateAction = namedtuple('DirectMessageAction', 'user message')
UnfollowAction = namedtuple('UnfollowAction', 'user')
ScrapeAction = namedtuple('ScrapeAction', 'source_name source_type user')
FilterAction = namedtuple('FilterAction', 'user')
Expand Down
55 changes: 33 additions & 22 deletions insomniac/device_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from os import listdir
from random import uniform
from re import search
from typing import Optional

from PIL.Image import Image

from insomniac.sleeper import sleeper
from insomniac.utils import *
Expand Down Expand Up @@ -64,7 +65,7 @@ def find(self, *args, **kwargs):
import uiautomator2
try:
view = self.deviceV2(*args, **kwargs)
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)
return DeviceFacade.View(is_old=False, view=view, device=self)

Expand Down Expand Up @@ -288,7 +289,7 @@ def swipe_points(self, sx, sy, ex, ey, duration=None):
self.deviceV2.swipe_points([[sx, sy], [ex, ey]], duration)
else:
self.deviceV2.swipe_points([[sx, sy], [ex, ey]], uniform(0.2, 0.6))
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)

def get_info(self):
Expand Down Expand Up @@ -361,7 +362,7 @@ def __iter__(self):
try:
for item in self.viewV2:
children.append(DeviceFacade.View(is_old=False, view=item, device=self.device))
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)
return iter(children)

Expand All @@ -377,7 +378,7 @@ def child(self, *args, **kwargs):
import uiautomator2
try:
view = self.viewV2.child(*args, **kwargs)
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)
return DeviceFacade.View(is_old=False, view=view, device=self.device)

Expand All @@ -393,7 +394,7 @@ def right(self, *args, **kwargs) -> Optional['DeviceFacade.View']:
import uiautomator2
try:
view = self.viewV2.right(*args, **kwargs)
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)
return DeviceFacade.View(is_old=False, view=view, device=self.device)

Expand All @@ -409,7 +410,7 @@ def left(self, *args, **kwargs):
import uiautomator2
try:
view = self.viewV2.left(*args, **kwargs)
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)
return DeviceFacade.View(is_old=False, view=view, device=self.device)

Expand All @@ -425,7 +426,7 @@ def up(self, *args, **kwargs):
import uiautomator2
try:
view = self.viewV2.up(*args, **kwargs)
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)
return DeviceFacade.View(is_old=False, view=view, device=self.device)

Expand All @@ -441,7 +442,7 @@ def down(self, *args, **kwargs):
import uiautomator2
try:
view = self.viewV2.down(*args, **kwargs)
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)
return DeviceFacade.View(is_old=False, view=view, device=self.device)

Expand Down Expand Up @@ -480,7 +481,7 @@ def click(self, mode=None, ignore_if_missing=False):
import uiautomator2
try:
self.viewV2.click(UI_TIMEOUT_LONG, offset=(x_offset, y_offset))
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)

def long_click(self):
Expand All @@ -494,7 +495,7 @@ def long_click(self):
import uiautomator2
try:
self.viewV2.long_click()
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)

def double_click(self, padding=0.3):
Expand Down Expand Up @@ -525,7 +526,7 @@ def scroll(self, direction):
self.viewV2.scroll.toBeginning(max_swipes=1)
else:
self.viewV2.scroll.toEnd(max_swipes=1)
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)

def swipe(self, direction):
Expand All @@ -545,7 +546,7 @@ def swipe(self, direction):
self.viewV2.fling.toBeginning(max_swipes=5)
else:
self.viewV2.fling.toEnd(max_swipes=5)
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)

def exists(self, quick=False):
Expand All @@ -559,7 +560,7 @@ def exists(self, quick=False):
import uiautomator2
try:
return self.viewV2.exists(UI_TIMEOUT_SHORT if quick else UI_TIMEOUT_LONG)
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)

def wait(self):
Expand All @@ -574,7 +575,7 @@ def wait(self):
import uiautomator2
try:
return self.viewV2.wait(timeout=UI_TIMEOUT_LONG)
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)

def get_bounds(self):
Expand All @@ -588,7 +589,7 @@ def get_bounds(self):
import uiautomator2
try:
return self.viewV2.info['bounds']
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)

def get_text(self, retry=True):
Expand Down Expand Up @@ -624,7 +625,7 @@ def get_text(self, retry=True):
continue
else:
return text
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)

print(COLOR_FAIL + f"Attempted to get text {attempts} times. You may have a slow network or are "
Expand All @@ -642,7 +643,7 @@ def get_selected(self) -> bool:
import uiautomator2
try:
return self.viewV2.info["selected"]
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)

def is_enabled(self) -> bool:
Expand All @@ -656,7 +657,7 @@ def is_enabled(self) -> bool:
import uiautomator2
try:
return self.viewV2.info["enabled"]
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)

def is_focused(self) -> bool:
Expand All @@ -670,7 +671,7 @@ def is_focused(self) -> bool:
import uiautomator2
try:
return self.viewV2.info["focused"]
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)

def set_text(self, text):
Expand All @@ -686,9 +687,19 @@ def set_text(self, text):
import uiautomator2
try:
self.viewV2.set_text(text)
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)

def get_image(self) -> Optional[Image]:
if self.viewV1 is not None:
print(COLOR_FAIL + "Obtaining views' images is not supported for old uiautomator" + COLOR_ENDC)
return None
else:
import uiautomator2
screenshot = self.device.deviceV2.screenshot()
bounds = self.get_bounds()
return screenshot.crop((bounds['left'], bounds['top'], bounds['right'], bounds['bottom']))

def _double_click_v1(self):
import uiautomator
config = self.device.deviceV1.server.jsonrpc.getConfigurator()
Expand Down Expand Up @@ -724,7 +735,7 @@ def _double_click_v2(self, padding):
time_between_clicks = uniform(0.050, 0.200)
try:
self.device.deviceV2.double_click(random_x, random_y, duration=time_between_clicks)
except uiautomator2.JSONRPCError as e:
except uiautomator2.JsonRpcError as e:
raise DeviceFacade.JsonRpcError(e)

@unique
Expand Down
1 change: 1 addition & 0 deletions insomniac/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,5 @@ def verify_instagram_version(installed_ig_version):
if insomniac_globals.is_insomniac():
print_timeless(COLOR_FAIL + "Please uninstall IG and download recommended apk from here:" + COLOR_ENDC)
print_timeless(COLOR_FAIL + COLOR_BOLD + "https://insomniac-bot.com/get_latest_supported_ig_apk/" + COLOR_ENDC)
input(COLOR_FAIL + "Press ENTER to continue anyway..." + COLOR_ENDC)
print_timeless("")
7 changes: 6 additions & 1 deletion insomniac/session_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from typing import Optional

from insomniac.actions_types import LikeAction, InteractAction, FollowAction, GetProfileAction, ScrapeAction, \
UnfollowAction, RemoveMassFollowerAction, StoryWatchAction, CommentAction, DirectMessageAction, FilterAction
UnfollowAction, RemoveMassFollowerAction, StoryWatchAction, CommentAction, DirectMessageAction, FilterAction, \
DirectMessageBackdateAction
from insomniac.storage import Storage, InsomniacStorage, SessionPhase


Expand Down Expand Up @@ -128,6 +129,10 @@ def add_action(self, action):
self.totalDirectMessages += 1
self.storage.log_direct_message_action(self.id, self.session_phase, action.user, action.message)

if type(action) == DirectMessageBackdateAction:
old_time_ago = datetime(2000, 1, 1, 0, 0, 0)
self.storage.log_direct_message_action(self.id, self.session_phase, action.user, action.message, old_time_ago)

if type(action) == UnfollowAction:
self.totalUnfollowed += 1
self.storage.log_unfollow_action(self.id, self.session_phase, action.user)
Expand Down
4 changes: 2 additions & 2 deletions insomniac/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def log_story_watch_action(self, session_id, phase, username, source_type, sourc
def log_comment_action(self, session_id, phase, username, comment, source_type, source_name):
self.profile.log_comment_action(session_id, phase.value, username, comment, source_type, source_name, insomniac_globals.task_id, insomniac_globals.execution_id)

def log_direct_message_action(self, session_id, phase, username, message):
self.profile.log_direct_message_action(session_id, phase.value, username, message, insomniac_globals.task_id, insomniac_globals.execution_id)
def log_direct_message_action(self, session_id, phase, username, message, timestamp=None):
self.profile.log_direct_message_action(session_id, phase.value, username, message, insomniac_globals.task_id, insomniac_globals.execution_id, timestamp)

def log_unfollow_action(self, session_id, phase, username):
self.profile.log_unfollow_action(session_id, phase.value, username, insomniac_globals.task_id, insomniac_globals.execution_id)
Expand Down
12 changes: 12 additions & 0 deletions insomniac/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import datetime
from enum import Enum, unique

from PIL.Image import Image

from insomniac.actions_types import GetProfileAction
from insomniac.counters_parser import parse
from insomniac.device_facade import DeviceFacade
Expand Down Expand Up @@ -1282,6 +1284,16 @@ def open_messages(self):
return True
return False

def get_profile_image(self) -> Optional[Image]:
profile_image_view = self.device.find(
resourceId=f"{self.device.app_id}:id/row_profile_header_imageview",
className="android.widget.ImageView",
)
if profile_image_view.exists(quick=True):
return profile_image_view.get_image()
else:
return None


class ProfileActionsView(InstagramView):

Expand Down

0 comments on commit e50d9e7

Please sign in to comment.