diff --git a/CHANGELOG.md b/CHANGELOG.md index 7870cde1..555cceeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,13 +4,17 @@ The **goal** of this file is explaining to the users of our project the notable _The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)_. -## [0.6.1] - 2019-xx-xx +## [0.6.2] - 2019-xx-xx ### Added - New bypass challenge approach (choose sms or email option) - Show InstaPy version on initialization +### Fixed + +- Login xpath + ## [0.6.1] - 2019-08-12 diff --git a/instapy/instapy.py b/instapy/instapy.py index 01a8733b..c0f90c40 100644 --- a/instapy/instapy.py +++ b/instapy/instapy.py @@ -89,6 +89,7 @@ from .pods_util import share_my_post_with_pods from .pods_util import share_with_pods_restriction from .pods_util import comment_restriction +from .pods_util import engage_with_posts from .xpath import read_xpath @@ -5661,12 +5662,6 @@ def join_pods(self, topic: str = "general", engagement_mode: str = "normal"): ) return self - if self.comments is not None and len(self.comments) < 10: - self.logger.error( - "You have too few comments, please set at least 10 distinct comments to avoid looking suspicious." - ) - return self - user_link = "https://www.instagram.com/{}/".format(self.username) web_address_navigator(self.browser, user_link) try: @@ -5743,29 +5738,16 @@ def join_pods(self, topic: str = "general", engagement_mode: str = "normal"): light_posts, normal_posts, heavy_posts = group_posts(pod_posts, self.logger) - self.logger.error("light_posts : {} ".format(light_posts)) - self.logger.error("normal_posts : {} ".format(normal_posts)) - self.logger.error("heavy_posts : {} ".format(heavy_posts)) - - self.engage_with_posts(light_posts, 10) - self.engage_with_posts(normal_posts, 30) - self.engage_with_posts(heavy_posts, 90) - - except Exception as err: - self.logger.error(err) - - return self + self.logger.info("light_posts : {} ".format(light_posts)) + self.logger.info("normal_posts : {} ".format(normal_posts)) + self.logger.info("heavy_posts : {} ".format(heavy_posts)) - def engage_with_posts(self, pod_posts, modespecific_comment_percentage): - for pod_post in pod_posts: - try: - pod_post_id = pod_post["postid"] - post_link = "https://www.instagram.com/p/{}".format(pod_post_id) - web_address_navigator(self.browser, post_link) - - inappropriate, user_name, is_video, reason, scope = check_link( + if len(light_posts) > 0: + engage_with_posts( self.browser, - post_link, + light_posts, + self.blacklist, + self.username, self.dont_like, self.mandatory_words, self.mandatory_language, @@ -5774,65 +5756,45 @@ def engage_with_posts(self, pod_posts, modespecific_comment_percentage): self.check_character_set, self.ignore_if_contains, self.logger, + self.logfolder + ) + if len(normal_posts) > 0: + engage_with_posts( + self.browser, + normal_posts, + self.blacklist, + self.username, + self.dont_like, + self.mandatory_words, + self.mandatory_language, + self.is_mandatory_character, + self.mandatory_character, + self.check_character_set, + self.ignore_if_contains, + self.logger, + self.logfolder + ) + if len(heavy_posts) > 0: + engage_with_posts( + self.browser, + heavy_posts, + self.blacklist, + self.username, + self.dont_like, + self.mandatory_words, + self.mandatory_language, + self.is_mandatory_character, + self.mandatory_character, + self.check_character_set, + self.ignore_if_contains, + self.logger, + self.logfolder ) - if user_name != self.username: - follow_state, msg = follow_user( - self.browser, - "post", - self.username, - user_name, - None, - self.blacklist, - self.logger, - self.logfolder, - ) - - self.dont_include.add(user_name) - - if not inappropriate and user_name != self.username: - pods_like_percent = max(90, min(100, self.like_percentage)) - liking = random.randint(0, 100) <= pods_like_percent - commenting = ( - random.randint(0, 100) <= modespecific_comment_percentage - ) - - if liking: - like_state, msg = like_image( - self.browser, - user_name, - self.blacklist, - self.logger, - self.logfolder, - self.liked_img, - ) - - if like_state is True: - self.liked_img += 1 - - elif msg == "block on likes": - break - - commenting_restricted = comment_restriction( - "read", pod_post_id, self.comment_times, self.logger - ) - - if commenting and not commenting_restricted: - comments = self.fetch_smart_comments(is_video, temp_comments=[]) - - comment_state, msg = comment_image( - self.browser, - user_name, - comments, - self.blacklist, - self.logger, - self.logfolder, - ) - if comment_state: - comment_restriction("write", pod_post_id, None, self.logger) + except Exception as err: + self.logger.error(err) - except Exception as err: - self.logger.error("Failed for {} with Error {}".format(pod_post, err)) + return self def story_by_tags(self, tags: list = None): """ Watch stories for specific tag(s) """ diff --git a/instapy/pods_util.py b/instapy/pods_util.py index 191fe652..3489e697 100644 --- a/instapy/pods_util.py +++ b/instapy/pods_util.py @@ -1,7 +1,12 @@ +import random import requests import sqlite3 + from .settings import Settings from .database_engine import get_database +from .like_util import like_image +from .like_util import check_link +from .util import web_address_navigator def get_server_endpoint(topic): @@ -40,6 +45,7 @@ def group_posts(posts, logger): light_post_ids = [] normal_post_ids = [] heavy_post_ids = [] + for postobj in posts: try: if postobj["mode"] == "light": @@ -207,3 +213,59 @@ def comment_restriction(operation, postid, limit, logger): if conn: # close the open connection conn.close() + + +# def engage_with_posts(browser, pod_posts): +def engage_with_posts( + browser, + pod_posts, + blacklist, + username, + dont_like, + mandatory_words, + mandatory_language, + is_mandatory_character, + mandatory_character, + check_character_set, + ignore_if_contains, + logger, + logfolder +): + liked_img = 0 + for pod_post in pod_posts: + try: + pod_post_id = pod_post["postid"] + post_link = "https://www.instagram.com/p/{}".format(pod_post_id) + web_address_navigator(browser, post_link) + + inappropriate, user_name, is_video, reason, scope = check_link( + browser, + post_link, # ok + dont_like, + mandatory_words, + mandatory_language, + is_mandatory_character, + mandatory_character, + check_character_set, + ignore_if_contains, + logger, + ) + + if not inappropriate and user_name != username: + like_state, msg = like_image( + browser, + user_name, + blacklist, + logger, + logfolder, + liked_img, + ) + + if like_state is True: + liked_img += 1 + + elif msg == "block on likes": + break + + except Exception as err: + logger.error("Failed for {} with Error {}".format(pod_post, err)) diff --git a/instapy/xpath_compile.py b/instapy/xpath_compile.py index 900c9ff9..5463dba2 100644 --- a/instapy/xpath_compile.py +++ b/instapy/xpath_compile.py @@ -153,8 +153,8 @@ xpath["login_user"] = { "input_password": "//input[@name='password']", "input_username_XP": "//input[@name='username']", - "login_elem": "//a[text()='Log in']", - "login_elem_no_such_exception": "//a[text()='Log In']", + "login_elem": "//button[text()='Log In']", + "login_elem_no_such_exception": "//a[text()='Log in']", "nav": "//nav", "website_status": "//span[@id='status']", "response_time": "//span[@id='response']",