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.7.26
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Mishchenko committed Sep 14, 2021
1 parent 1d5f0e8 commit bee516d
Show file tree
Hide file tree
Showing 24 changed files with 427 additions and 160 deletions.
22 changes: 19 additions & 3 deletions insomniac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from insomniac import network
from insomniac.activation import activation_controller
from insomniac.network import HTTP_OK
from insomniac.params import parse_arguments
from insomniac.params import parse_arguments, load_param
from insomniac.utils import *


Expand All @@ -17,7 +17,7 @@ def run(activation_code="", starter_conf_file_path=None):
print_timeless(COLOR_OKGREEN + __version__.__logo__ + COLOR_ENDC)
print_version()

activation_code_from_args = get_arg_value(ACTIVATION_CODE_ARG_NAME)
activation_code_from_args = get_arg_value(ACTIVATION_CODE_ARG_NAME, starter_conf_file_path)
if activation_code_from_args is not None:
activation_code = activation_code_from_args

Expand Down Expand Up @@ -60,7 +60,16 @@ def _get_latest_version(package):
return latest_version


def get_arg_value(arg_name):
def get_arg_value(arg_name, conf_path):
arg_from_cli = get_arg_value_from_cli(arg_name)

if arg_from_cli is not None:
return arg_from_cli

return get_arg_value_from_config_file(arg_name, conf_path)


def get_arg_value_from_cli(arg_name):
parser = ArgumentParser(add_help=False)
parser.add_argument(f'--{arg_name.replace("_", "-")}')
try:
Expand All @@ -70,6 +79,13 @@ def get_arg_value(arg_name):
return getattr(args, arg_name)


def get_arg_value_from_config_file(arg_name, conf_file_path):
if conf_file_path is None:
return None

return load_param(conf_file_path, arg_name)


class ArgumentParser(argparse.ArgumentParser):

def error(self, message):
Expand Down
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.7.25'
__version__ = '3.7.26'
__debug_mode__ = False
__author__ = 'Insomniac Team'
__author_email__ = 'info@insomniac-bot.com'
Expand Down
2 changes: 1 addition & 1 deletion insomniac/action_runners/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from insomniac.action_runners.core import ActionsRunner, CoreActionsRunner, ActionStatus, ActionState
from insomniac.action_runners.core import ActionsRunner, InsomniacActionsRunner, CoreActionsRunner, ActionStatus, ActionState
from insomniac.action_runners.interact import InteractBySourceActionRunner, InteractByTargetsActionRunner
from insomniac.action_runners.unfollow import UnfollowActionRunner

Expand Down
10 changes: 7 additions & 3 deletions insomniac/action_runners/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_limit(self):
return self.limit_state


class ActionsRunner(object):
class ActionsRunner(ABC):
"""An interface for actions-runner object"""

ACTION_ID = "OVERRIDE"
Expand All @@ -46,9 +46,13 @@ def set_params(self, args):
def reset_params(self):
raise NotImplementedError()


class InsomniacActionsRunner(ActionsRunner, ABC):
"""An interface for extra-actions-runner object"""

def run(self, device_wrapper, storage, session_state, on_action, is_limit_reached, is_passed_filters=None):
raise NotImplementedError()


class CoreActionsRunner(ActionsRunner, ABC):
"""An interface for extra-actions-runner object"""
class CoreActionsRunner(InsomniacActionsRunner, ABC):
"""An interface for core-actions-runner object"""
6 changes: 3 additions & 3 deletions insomniac/action_runners/interact/action_handle_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CommentAction, TargetType, FilterAction
from insomniac.limits import process_limits
from insomniac.report import print_short_report, print_interaction_types
from insomniac.session_state import SessionState
from insomniac.session_state import InsomniacSessionState
from insomniac.sleeper import sleeper
from insomniac.storage import FollowingStatus
from insomniac.utils import *
Expand Down Expand Up @@ -134,7 +134,7 @@ def interact_with_username_target(target_name, target_name_view):
is_liked, is_followed, is_watch, is_commented = interaction(username=target_name, interaction_strategy=interaction_strategy)
if is_liked or is_followed or is_watch or is_commented:
on_action(InteractAction(source_name=target, source_type=source_type, user=target_name, succeed=True))
print_short_report(SessionState.SOURCE_NAME_TARGETS, session_state)
print_short_report(InsomniacSessionState.SOURCE_NAME_TARGETS, session_state)
else:
on_action(InteractAction(source_name=target, source_type=source_type, user=target_name, succeed=False))

Expand Down Expand Up @@ -181,7 +181,7 @@ def interact_with_post_id_target(target_post, target_username, target_name_view)
print(COLOR_OKGREEN + f"@{target_username} - {target_post} - photo been liked." + COLOR_ENDC)
on_action(LikeAction(source_name=target_username, source_type=source_type, user=target_username))
on_action(InteractAction(source_name=target_username, source_type=source_type, user=target_username, succeed=True))
print_short_report(SessionState.SOURCE_NAME_TARGETS, session_state)
print_short_report(InsomniacSessionState.SOURCE_NAME_TARGETS, session_state)

if is_like_limit_reached:
# If one of the limits reached for source-limit, move to next source
Expand Down
File renamed without changes.
Binary file added insomniac/assets/aapt
Binary file not shown.
108 changes: 99 additions & 9 deletions insomniac/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from insomniac.globals import executable_name

DATABASE_NAME = f'{executable_name}.db'
DATABASE_VERSION = 3
DATABASE_VERSION = 4

db = SqliteDatabase(DATABASE_NAME, autoconnect=False)

Expand Down Expand Up @@ -72,16 +72,25 @@ def add_session(self, app_id, app_version, args, profile_status, followers_count
def update_profile_info(self, profile_status, followers_count, following_count):
"""
Create a new InstagramProfileInfo record
Can't see any usage for that right now, maybe we will use it later just in order to update profile info without
running an insomniac-session.
"""
with db.connection_context():
InstagramProfileInfo.create(profile=self,
status=profile_status,
status=profile_status.value,
followers=followers_count,
following=following_count)

def get_latsest_profile_info(self) -> Optional['InstagramProfileInfo']:
with db.connection_context():
query = InstagramProfileInfo.select() \
.where(InstagramProfileInfo.profile == self) \
.group_by(InstagramProfileInfo.profile) \
.having(InstagramProfileInfo.timestamp == fn.MAX(InstagramProfileInfo.timestamp))

for obj in query:
return obj

return None

def log_get_profile_action(self, session_id, phase, username, task_id='', execution_id='', timestamp=None):
"""
Create InsomniacAction record
Expand Down Expand Up @@ -281,6 +290,20 @@ def log_change_profile_info_action(self, session_id, phase, profile_pic_url, nam
name=name,
description=description)

def log_management_action(self, session_id, management_action_type, management_action_params, phase, task_id='', execution_id='', timestamp=None):
with db.connection_context():
session = SessionInfo.get(SessionInfo.id == session_id)
action = InsomniacAction.create(actor_profile=self,
type=management_action_type.__name__,
task_id=task_id,
execution_id=execution_id,
session=session,
phase=phase,
timestamp=(timestamp if timestamp is not None else datetime.now()))

params = {**management_action_params, **{'action': action}}
management_action_type.create(**params)

def publish_scrapped_account(self, username, scrape_for_account_list):
"""
Use this function when you are a scrapper and you have found a profile according to filters.
Expand Down Expand Up @@ -492,8 +515,8 @@ class InsomniacAction(InsomniacModel):
actor_profile = ForeignKeyField(InstagramProfile, backref='actions')
type = TextField()
timestamp = TimestampField(default=datetime.now)
task_id = UUIDField()
execution_id = UUIDField()
task_id = TextField()
execution_id = TextField()
session = ForeignKeyField(SessionInfo, backref='session_actions')
phase = TextField(default='task')

Expand Down Expand Up @@ -616,6 +639,51 @@ class Meta:
db_table = 'follow_status'


class CloneCreationAction(InsomniacModel):
action = ForeignKeyField(InsomniacAction, backref='clone_creation_action_info')
username = TextField()
device = TextField()

class Meta:
db_table = 'clone_creation_actions'


class CloneInstallationAction(InsomniacModel):
action = ForeignKeyField(InsomniacAction, backref='clone_installation_action_info')
username = TextField()
device = TextField()

class Meta:
db_table = 'clone_installation_actions'


class CloneRemovalAction(InsomniacModel):
action = ForeignKeyField(InsomniacAction, backref='clone_removal_action_info')
username = TextField()
device = TextField()

class Meta:
db_table = 'clone_removal_actions'


class AppDataCleanupAction(InsomniacModel):
action = ForeignKeyField(InsomniacAction, backref='app_data_cleanup_action_info')
username = TextField()
device = TextField()

class Meta:
db_table = 'app_data_cleanup_actions'


class ProfileRegistrationAction(InsomniacModel):
action = ForeignKeyField(InsomniacAction, backref='profile_registration_action_info')
username = TextField()
device = TextField()

class Meta:
db_table = 'profile_registration_actions'


class SchemaVersion(InsomniacModel):
version = SmallIntegerField(default=DATABASE_VERSION)
updated_at = TimestampField(default=datetime.now)
Expand All @@ -642,7 +710,12 @@ class Meta:
FilterAction,
ChangeProfileInfoAction,
ScrappedProfile,
FollowStatus
FollowStatus,
CloneCreationAction,
CloneInstallationAction,
CloneRemovalAction,
AppDataCleanupAction,
ProfileRegistrationAction
]


Expand Down Expand Up @@ -872,6 +945,18 @@ def _migrate_db_from_version_2_to_3(migrator):
)


def _migrate_db_from_version_3_to_4(migrator):
"""
Changes added on DB version 4:
* Added tables: CloneCreationAction, CloneInstallationAction,
CloneRemovalAction, AppDataCleanupAction, ProfileRegistrationAction
"""
new_tables = [CloneCreationAction, CloneInstallationAction, CloneRemovalAction,
AppDataCleanupAction, ProfileRegistrationAction]

db.create_tables(new_tables)


def _migrate(curr_version, migrator):
print(f"[Database] Going to run database migration from version {curr_version} to {curr_version+1}")
migration_method = database_migrations[f"{curr_version}->{curr_version + 1}"]
Expand All @@ -884,5 +969,10 @@ def _migrate(curr_version, migrator):

database_migrations = {
"1->2": _migrate_db_from_version_1_to_2,
"2->3": _migrate_db_from_version_2_to_3
"2->3": _migrate_db_from_version_2_to_3,
"3->4": _migrate_db_from_version_3_to_4
}


class QueryIsNotAllowedException(Exception):
pass
3 changes: 3 additions & 0 deletions insomniac/extra_features/action_manage_clones.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from insomniac import activation_controller

exec(activation_controller.get_extra_feature('action_manage_clones'))
3 changes: 3 additions & 0 deletions insomniac/extra_features/management_actions_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from insomniac import activation_controller

exec(activation_controller.get_extra_feature('management_actions_types'))
3 changes: 3 additions & 0 deletions insomniac/extra_features/report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from insomniac import activation_controller

exec(activation_controller.get_extra_feature('report'))
3 changes: 3 additions & 0 deletions insomniac/extra_features/session_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from insomniac import activation_controller

exec(activation_controller.get_extra_feature('session_state'))
3 changes: 3 additions & 0 deletions insomniac/extra_features/storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from insomniac import activation_controller

exec(activation_controller.get_extra_feature('storage'))
8 changes: 8 additions & 0 deletions insomniac/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@
do_location_permission_dialog_checks = True # no need in these checks if location permission is denied beforehand


def callback(profile_name):
pass


hardban_detected_callback = callback
softban_detected_callback = callback


def is_insomniac():
return execution_id == ''
37 changes: 37 additions & 0 deletions insomniac/hardban_indicator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from insomniac.utils import *


class HardBanError(Exception):
pass


class HardBanIndicator:

WEBVIEW_ACTIVITY_NAME = 'com.instagram.simplewebview.SimpleWebViewActivity'

def detect_webview(self, device):
"""
While "hard banned" Instagram shows you a webview with CAPTCHA and request to confirm your account. So what we
need is to simply detect that topmost activity is a webview.
"""
device_id = device.device_id
app_id = device.app_id
resumed_activity_output = execute_command("adb" + ("" if device_id is None else " -s " + device_id) +
f" shell dumpsys activity | grep 'mResumedActivity'")

max_attempts = 3
attempt = 1
while attempt <= max_attempts:
sleep(1)
full_webview_activity_name = f"{app_id}/{self.WEBVIEW_ACTIVITY_NAME}"
if resumed_activity_output is not None and full_webview_activity_name in resumed_activity_output:
print(COLOR_FAIL + "WebView is shown. Counting that as a hard-ban indicator!" + COLOR_ENDC)
self.indicate_ban()
return
attempt += 1

def indicate_ban(self):
raise HardBanError("Hard ban indicated!")


hardban_indicator = HardBanIndicator()
4 changes: 2 additions & 2 deletions insomniac/migration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json

from insomniac.db_models import DATABASE_NAME, is_ig_profile_exists
from insomniac.session_state import SessionState
from insomniac.session_state import InsomniacSessionState
from insomniac.sessions import FILENAME_SESSIONS, Sessions
from insomniac.storage import *
from insomniac.utils import *
Expand Down Expand Up @@ -115,7 +115,7 @@ def migrate_from_json_to_sql(my_username):
with open(sessions_path, encoding="utf-8") as json_file:
sessions = json.load(json_file)
for session in sessions:
session_state = SessionState()
session_state = InsomniacSessionState()
session_state.id = session["id"]
session_state.args = str(session["args"])
session_state.app_version = session.get("app_version", "")
Expand Down
Loading

0 comments on commit bee516d

Please sign in to comment.