AutoMark/InstaPy/instapy/instapy.py
def interact_by_users(self,
                          usernames,
                          amount=10,
                          randomize=False,
                          media=None):
        """Likes some amounts of images for each usernames"""
        if self.aborting:
            return self

        total_liked_img = 0
        already_liked = 0
        inap_img = 0
        commented = 0
        followed = 0

        usernames = usernames or []

        for index, username in enumerate(usernames):
            self.logger.info(
                'Username [{}/{}]'.format(index + 1, len(usernames)))
            self.logger.info('--> {}'.format(username.encode('utf-8')))

            try:
                links = get_links_for_username(self.browser,
                                               username,
                                               amount,
                                               self.logger,
                                               randomize,
                                               media)
            except NoSuchElementException:
                self.logger.error('Element not found, skipping this username')
                continue

            if links is False:
                continue

            # Reset like counter for every username
            liked_img = 0

            for i, link in enumerate(links):
                # Check if target has reached
                if liked_img >= amount:
                    self.logger.info('-------------')
                    self.logger.info("--> Total liked image reached it's "
                                     "amount given: {}".format(liked_img))
                    break

                self.logger.info('Post [{}/{}]'.format(liked_img + 1, amount))
                self.logger.info(link)

                try:
                    inappropriate, user_name, is_video, reason = (
                        check_link(self.browser,
                                   link,
                                   self.dont_like,
                                   self.ignore_if_contains,
                                   self.ignore_users,
                                   self.username,
                                   self.like_by_followers_upper_limit,
                                   self.like_by_followers_lower_limit,
                                   self.logger)
                    )

                    if not inappropriate:

                        following = (
                            random.randint(0, 100) <= self.follow_percentage)
                        if (self.do_follow and
                            username not in self.dont_include and
                            following and
                            self.follow_restrict.get(
                                username, 0) < self.follow_times):

                            followed += follow_user(
                                self.browser,
                                self.follow_restrict,
                                self.username,
                                username,
                                self.blacklist,
                                self.logger,
                                self.logfolder)
                        else:
                            self.logger.info('--> Not following')
                            sleep(1)

                        liking = random.randint(0, 100) <= self.like_percentage
                        if self.do_like and liking:
                            liked = like_image(self.browser,
                                               user_name,
                                               self.blacklist,
                                               self.logger,
                                               self.logfolder)
                        else:
                            liked = True

                        if liked:
                            total_liked_img += 1
                            liked_img += 1
                            checked_img = True
                            temp_comments = []
                            commenting = random.randint(
                                0, 100) <= self.comment_percentage

                            if self.use_clarifai and (following or commenting):
                                try:
                                    checked_img, temp_comments = (
                                        check_image(self.browser,
                                                    self.clarifai_api_key,
                                                    self.clarifai_img_tags,
                                                    self.logger,
                                                    self.clarifai_full_match)
                                    )
                                except Exception as err:
                                    self.logger.error(
                                        'Image check error: {}'.format(err))
                            if (self.do_comment and
                                user_name not in self.dont_include and
                                checked_img and
                                    commenting):

                                if temp_comments:
                                    # use clarifai related comments only!
                                    comments = temp_comments
                                elif is_video:
                                    comments = (self.comments +
                                                self.video_comments)
                                else:
                                    comments = (self.comments +
                                                self.photo_comments)
                                commented += comment_image(self.browser,
                                                           user_name,
                                                           comments,
                                                           self.blacklist,
                                                           self.logger,
                                                           self.logfolder)
                            else:
                                self.logger.info('--> Not commented')
                                sleep(1)
                        else:
                            already_liked += 1

                    else:
                        self.logger.info(
                            '--> Image not liked: {}'.format(reason.encode('utf-8')))
                        inap_img += 1
                except NoSuchElementException as err:
                    self.logger.info('Invalid Page: {}'.format(err))

            if liked_img < amount:
                self.logger.info('-------------')
                self.logger.info("--> Given amount not fullfilled, image pool "
                                 "reached its end\n")

        self.logger.info('Liked: {}'.format(total_liked_img))
        self.logger.info('Already Liked: {}'.format(already_liked))
        self.logger.info('Inappropriate: {}'.format(inap_img))
        self.logger.info('Commented: {}'.format(commented))

        self.liked_img += liked_img
        self.already_liked += already_liked
        self.inap_img += inap_img
        self.commented += commented

        return self
Likes some amounts of images for each usernames
Likes some amounts of images for each usernames
Likes some amounts of images for each usernames
def interact_by_users(self,
                          usernames,
                          amount=10,
                          randomize=False,
                          media=None):
        if self.aborting:
            return self
        total_liked_img = 0
        already_liked = 0
        inap_img = 0
        commented = 0
        followed = 0
        usernames = usernames or []
        for index, username in enumerate(usernames):
            self.logger.info(
                'Username [{}/{}]'.format(index + 1, len(usernames)))
            self.logger.info('--> {}'.format(username.encode('utf-8')))
            try:
                links = get_links_for_username(self.browser,
                                               username,
                                               amount,
                                               self.logger,
                                               randomize,
                                               media)
            except NoSuchElementException:
                self.logger.error('Element not found, skipping this username')
                continue
            if links is False:
                continue
            liked_img = 0
            for i, link in enumerate(links):
                if liked_img >= amount:
                    self.logger.info('-------------')
                    self.logger.info("--> Total liked image reached it's "
                                     "amount given: {}".format(liked_img))
                    break
                self.logger.info('Post [{}/{}]'.format(liked_img + 1, amount))
                self.logger.info(link)
                try:
                    inappropriate, user_name, is_video, reason = (
                        check_link(self.browser,
                                   link,
                                   self.dont_like,
                                   self.ignore_if_contains,
                                   self.ignore_users,
                                   self.username,
                                   self.like_by_followers_upper_limit,
                                   self.like_by_followers_lower_limit,
                                   self.logger)
                    )
                    if not inappropriate:
                        following = (
                            random.randint(0, 100) <= self.follow_percentage)
                        if (self.do_follow and
                            username not in self.dont_include and
                            following and
                            self.follow_restrict.get(
                                username, 0) < self.follow_times):
                            followed += follow_user(
                                self.browser,
                                self.follow_restrict,
                                self.username,
                                username,
                                self.blacklist,
                                self.logger,
                                self.logfolder)
                        else:
                            self.logger.info('--> Not following')
                            sleep(1)
                        liking = random.randint(0, 100) <= self.like_percentage
                        if self.do_like and liking:
                            liked = like_image(self.browser,
                                               user_name,
                                               self.blacklist,
                                               self.logger,
                                               self.logfolder)
                        else:
                            liked = True
                        if liked:
                            total_liked_img += 1
                            liked_img += 1
                            checked_img = True
                            temp_comments = []
                            commenting = random.randint(
                                0, 100) <= self.comment_percentage
                            if self.use_clarifai and (following or commenting):
                                try:
                                    checked_img, temp_comments = (
                                        check_image(self.browser,
                                                    self.clarifai_api_key,
                                                    self.clarifai_img_tags,
                                                    self.logger,
                                                    self.clarifai_full_match)
                                    )
                                except Exception as err:
                                    self.logger.error(
                                        'Image check error: {}'.format(err))
                            if (self.do_comment and
                                user_name not in self.dont_include and
                                checked_img and
                                    commenting):
                                if temp_comments:
                                    comments = temp_comments
                                elif is_video:
                                    comments = (self.comments +
                                                self.video_comments)
                                else:
                                    comments = (self.comments +
                                                self.photo_comments)
                                commented += comment_image(self.browser,
                                                           user_name,
                                                           comments,
                                                           self.blacklist,
                                                           self.logger,
                                                           self.logfolder)
                            else:
                                self.logger.info('--> Not commented')
                                sleep(1)
                        else:
                            already_liked += 1
                    else:
                        self.logger.info(
                            '--> Image not liked: {}'.format(reason.encode('utf-8')))
                        inap_img += 1
                except NoSuchElementException as err:
                    self.logger.info('Invalid Page: {}'.format(err))
            if liked_img < amount:
                self.logger.info('-------------')
                self.logger.info("--> Given amount not fullfilled, image pool "
                                 "reached its end\n")
        self.logger.info('Liked: {}'.format(total_liked_img))
        self.logger.info('Already Liked: {}'.format(already_liked))
        self.logger.info('Inappropriate: {}'.format(inap_img))
        self.logger.info('Commented: {}'.format(commented))
        self.liked_img += liked_img
        self.already_liked += already_liked
        self.inap_img += inap_img
        self.commented += commented
        return self
def interact_by_users ( self , usernames , amount = 10 , randomize = False , media = None ) : if self . aborting : return self total_liked_img = 0 already_liked = 0 inap_img = 0 commented = 0 followed = 0 usernames = usernames or [ ] for index , username in enumerate ( usernames ) : self . logger . info ( 'Username [{}/{}]' . format ( index + 1 , len ( usernames ) ) ) self . logger . info ( '--> {}' . format ( username . encode ( 'utf-8' ) ) ) try : links = get_links_for_username ( self . browser , username , amount , self . logger , randomize , media ) except NoSuchElementException : self . logger . error ( 'Element not found, skipping this username' ) continue if links is False : continue liked_img = 0 for i , link in enumerate ( links ) : if liked_img >= amount : self . logger . info ( '-------------' ) self . logger . info ( "--> Total liked image reached it's " "amount given: {}" . format ( liked_img ) ) break self . logger . info ( 'Post [{}/{}]' . format ( liked_img + 1 , amount ) ) self . logger . info ( link ) try : inappropriate , user_name , is_video , reason = ( check_link ( self . browser , link , self . dont_like , self . ignore_if_contains , self . ignore_users , self . username , self . like_by_followers_upper_limit , self . like_by_followers_lower_limit , self . logger ) ) if not inappropriate : following = ( random . randint ( 0 , 100 ) <= self . follow_percentage ) if ( self . do_follow and username not in self . dont_include and following and self . follow_restrict . get ( username , 0 ) < self . follow_times ) : followed += follow_user ( self . browser , self . follow_restrict , self . username , username , self . blacklist , self . logger , self . logfolder ) else : self . logger . info ( '--> Not following' ) sleep ( 1 ) liking = random . randint ( 0 , 100 ) <= self . like_percentage if self . do_like and liking : liked = like_image ( self . browser , user_name , self . blacklist , self . logger , self . logfolder ) else : liked = True if liked : total_liked_img += 1 liked_img += 1 checked_img = True temp_comments = [ ] commenting = random . randint ( 0 , 100 ) <= self . comment_percentage if self . use_clarifai and ( following or commenting ) : try : checked_img , temp_comments = ( check_image ( self . browser , self . clarifai_api_key , self . clarifai_img_tags , self . logger , self . clarifai_full_match ) ) except Exception as err : self . logger . error ( 'Image check error: {}' . format ( err ) ) if ( self . do_comment and user_name not in self . dont_include and checked_img and commenting ) : if temp_comments : comments = temp_comments elif is_video : comments = ( self . comments + self . video_comments ) else : comments = ( self . comments + self . photo_comments ) commented += comment_image ( self . browser , user_name , comments , self . blacklist , self . logger , self . logfolder ) else : self . logger . info ( '--> Not commented' ) sleep ( 1 ) else : already_liked += 1 else : self . logger . info ( '--> Image not liked: {}' . format ( reason . encode ( 'utf-8' ) ) ) inap_img += 1 except NoSuchElementException as err : self . logger . info ( 'Invalid Page: {}' . format ( err ) ) if liked_img < amount : self . logger . info ( '-------------' ) self . logger . info ( "--> Given amount not fullfilled, image pool " "reached its end\n" ) self . logger . info ( 'Liked: {}' . format ( total_liked_img ) ) self . logger . info ( 'Already Liked: {}' . format ( already_liked ) ) self . logger . info ( 'Inappropriate: {}' . format ( inap_img ) ) self . logger . info ( 'Commented: {}' . format ( commented ) ) self . liked_img += liked_img self . already_liked += already_liked self . inap_img += inap_img self . commented += commented return self
Likes some amounts of images for each usernames
Likes some amounts of images for each usernames
"""Likes some amounts of images for each usernames""" # Reset like counter for every username # Check if target has reached # use clarifai related comments only!
self
usernames
amount
randomize
media