Skip to content

Commit

Permalink
Update to v3.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Mishchenko committed Apr 3, 2021
1 parent afe5e2a commit 63a1f3f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 49 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.7.1'
__version__ = '3.7.2'
__debug_mode__ = False
__author__ = 'Insomniac Team'
__author_email__ = 'info@insomniac-bot.com'
Expand Down
9 changes: 5 additions & 4 deletions insomniac/actions_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def _watch_stories(device, source_name, source_type, username, stories_value, on
return False

def story_sleep():
delay = uniform(0, 3)
delay = uniform(1, 5)
print(f"Sleep for {delay:.2f} seconds")
sleep(delay)

Expand All @@ -577,12 +577,13 @@ def story_sleep():

profile_picture.click() # Open the first story
on_action(StoryWatchAction(source_name=source_name, source_type=source_type, user=username))
story_sleep()
sleeper.random_sleep()

for i in range(1, stories_value):
print("Watching a story...")
story_sleep()
if _skip_story(device):
print("Watching next story...")
story_sleep()
print("Go next")
else:
print(COLOR_OKGREEN + "Watched all stories" + COLOR_ENDC)
break
Expand Down
73 changes: 36 additions & 37 deletions insomniac/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,52 +373,51 @@ def is_scrapped(self, username, scrape_for_account_list) -> bool:
return False
return True

def count_scrapped_profiles_for_interaction(self):
with db.connection_context():
return len(self._get_scrapped_profiles_query())

def get_scrapped_profile_for_interaction(self) -> Optional[str]:
"""
Use this function when you are interacting with targets, and you are looking for the next scrapped target
"""
with db.connection_context():
scrapped_profiles = ScrappedProfile.select(ScrappedProfile.name) \
.where(ScrappedProfile.target_actor_profile == self) \
.join(GetProfileAction, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == GetProfileAction.target_user)) \
.switch(ScrappedProfile) \
.join(LikeAction, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == LikeAction.target_user)) \
.switch(ScrappedProfile) \
.join(FollowAction, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == FollowAction.target_user)) \
.switch(ScrappedProfile) \
.join(StoryWatchAction, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == StoryWatchAction.target_user)) \
.switch(ScrappedProfile) \
.join(CommentAction, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == CommentAction.target_user)) \
.where(
GetProfileAction.target_user.is_null()
& LikeAction.target_user.is_null()
& FollowAction.target_user.is_null()
& StoryWatchAction.target_user.is_null()
& CommentAction.target_user.is_null()
) \
scrapped_profiles = self._get_scrapped_profiles_query() \
.order_by(ScrappedProfile.timestamp.desc()) \
.limit(1)

return scrapped_profiles[0].name if len(scrapped_profiles) > 0 else None

def count_scrapped_profiles_for_interaction(self):
with db.connection_context():
return len(ScrappedProfile.select(ScrappedProfile.name)
.where(ScrappedProfile.target_actor_profile == self)
.join(GetProfileAction, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == GetProfileAction.target_user))
.switch(ScrappedProfile)
.join(LikeAction, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == LikeAction.target_user))
.switch(ScrappedProfile)
.join(FollowAction, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == FollowAction.target_user))
.switch(ScrappedProfile)
.join(StoryWatchAction, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == StoryWatchAction.target_user))
.switch(ScrappedProfile)
.join(CommentAction, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == CommentAction.target_user))
.where(GetProfileAction.target_user.is_null()
& LikeAction.target_user.is_null()
& FollowAction.target_user.is_null()
& StoryWatchAction.target_user.is_null()
& CommentAction.target_user.is_null()))
def _get_scrapped_profiles_query(self):
def get_profiles_reached_by_action(action):
return (action
.select(action.target_user)
.join(InsomniacAction)
.where(InsomniacAction.actor_profile == self))

profiles_reached_by_get_profile = get_profiles_reached_by_action(GetProfileAction)
profiles_reached_by_like = get_profiles_reached_by_action(LikeAction)
profiles_reached_by_follow = get_profiles_reached_by_action(FollowAction)
profiles_reached_by_story_watch = get_profiles_reached_by_action(StoryWatchAction)
profiles_reached_by_comment = get_profiles_reached_by_action(CommentAction)

return (ScrappedProfile.select(ScrappedProfile.name)
.where(ScrappedProfile.target_actor_profile == self)
.join(profiles_reached_by_get_profile, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == profiles_reached_by_get_profile.c.target_user))
.switch(ScrappedProfile)
.join(profiles_reached_by_like, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == profiles_reached_by_like.c.target_user))
.switch(ScrappedProfile)
.join(profiles_reached_by_follow, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == profiles_reached_by_follow.c.target_user))
.switch(ScrappedProfile)
.join(profiles_reached_by_story_watch, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == profiles_reached_by_story_watch.c.target_user))
.switch(ScrappedProfile)
.join(profiles_reached_by_comment, join_type=JOIN.LEFT_OUTER, on=(ScrappedProfile.name == profiles_reached_by_comment.c.target_user))
.where(
profiles_reached_by_get_profile.c.target_user.is_null()
& profiles_reached_by_like.c.target_user.is_null()
& profiles_reached_by_follow.c.target_user.is_null()
& profiles_reached_by_story_watch.c.target_user.is_null()
& profiles_reached_by_comment.c.target_user.is_null()
))


class InstagramProfileInfo(InsomniacModel):
Expand Down
12 changes: 6 additions & 6 deletions insomniac/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ def migrate_from_sql_to_peewee(my_username):
print(f"[Migration] Migrating sessions to the {DATABASE_NAME}...")
for session in get_all_sessions(database):
my_profile.add_session(None,
session["app_version"],
session["args"],
session["app_version"] or "",
session["args"] or "",
ProfileStatus.VALID,
session["followers"],
session["following"],
datetime.strptime(session["start_time"], '%Y-%m-%d %H:%M:%S.%f'),
datetime.strptime(session["finish_time"], '%Y-%m-%d %H:%M:%S.%f'))
session["followers"] or -1,
session["following"] or -1,
datetime.strptime(session["start_time"] or datetime.now(), '%Y-%m-%d %H:%M:%S.%f'),
datetime.strptime(session["finish_time"] or datetime.now(), '%Y-%m-%d %H:%M:%S.%f'))

session_id = my_profile.start_session(None, "Unknown app version: migration", "Unknown args: migration", ProfileStatus.VALID, -1, -1)
print(f"[Migration] Migrating interacted users to the {DATABASE_NAME}...")
Expand Down
17 changes: 16 additions & 1 deletion insomniac/tests/db_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def job_real(profile, session_id):
assert username == username4

print(COLOR_BOLD + "Real: check account is excluded after story-watch-interaction" + COLOR_ENDC)
profile.log_comment_action(session_id, username4, "Wow!", SourceType.BLOGGER.name, "some_blogger")
profile.log_story_watch_action(session_id, username4, SourceType.BLOGGER.name, "some_blogger")
username = profile.get_scrapped_profile_for_interaction()
assert username == username5

Expand Down Expand Up @@ -257,6 +257,21 @@ def job_real(profile, _):
assert username == username7
self._run_inside_session(real_account_username, job_real)

def job_real(profile, session_id):
print(f"Real: interact with {username7} from another account")
profile.log_get_profile_action(session_id, username7)
profile.log_like_action(session_id, username7, SourceType.BLOGGER.name, "some_blogger")
profile.log_follow_action(session_id, username7, SourceType.HASHTAG.name, "some_hashtag")
profile.log_story_watch_action(session_id, username7, SourceType.BLOGGER.name, "some_blogger")
profile.log_comment_action(session_id, username7, "Wow!", SourceType.PLACE.name, "some_place")
self._run_inside_session("some_another_account", job_real)

def job_real(profile, _):
print(COLOR_BOLD + "Real: check account is still accepted after interacted by another account" + COLOR_ENDC)
username = profile.get_scrapped_profile_for_interaction()
assert username == username7
self._run_inside_session(real_account_username, job_real)

def tearDown(self):
print("Deleting test database")
os.remove(TEST_DATABASE_FILE)
Expand Down

0 comments on commit 63a1f3f

Please sign in to comment.