Example #1
0
        public async Task RunAsync()
        {
            _logger.LogTrace("RunAsync()");

            await _seleniumWrapper.ScrollToTopAsync();

            // open if require
            if (_seleniumWrapper.CurrentUrl != _persistenceManager.Session.UserContactUrl)
            {
                await _seleniumWrapper.Click(_instagramOptions.CssHeaderMyself);
                await _seleniumWrapper.Click(_instagramOptions.CssHeaderMyselfProfile); // must be here, else the auth have failed
            }

            // need to get a new list
            HashSet<string> myFollowers = await GetMyFollowers();

            // open Following popup
            await _seleniumWrapper.Click(_instagramOptions.CssContactsFollowing);

            // loop until no more element
            await _seleniumWrapper.ScrollToBottomAsync(_instagramOptions.CssContactsListScrollable);

            // Get the list
            HashSet<string> myFollowing = new HashSet<string>(_seleniumWrapper.GetAttributes(_instagramOptions.CssContactUrl));
            myFollowing.ExceptWith(myFollowers);
            _logger.LogDebug("Found {0} currently followed but not follower", myFollowing.Count);

            // find
            int unfollowDone = 0;
            int unfollowTodo = PseudoRandom.Next(_unfollowUnfollowersOptions.UnfollowMin, _unfollowUnfollowersOptions.UnfollowMax);
            IWebElement element = GetNextElement(myFollowing);
            while (element != null && unfollowDone < unfollowTodo)
            {
                _logger.LogDebug("Unfollowing");

                // Unfollowing popup
                await _seleniumWrapper.ScrollIntoView(element, thenWait: false); //  bigger waiter altready present after
                await _waitAction.PreFollowWait();
                await _seleniumWrapper.Click(element);

                // Unfollowing action
                await _seleniumWrapper.Click(_instagramOptions.CssContactUnfollowConfirm);

                _seleniumWrapper.CrashIfPresent(_instagramOptions.CssActionWarning, InstagramOptions.CssActionWarningErrorMessage);
                unfollowDone++;

                // prepare next
                element = GetNextElement(myFollowing);
            }
            if (unfollowDone == unfollowTodo)
            {
                _logger.LogDebug("Unfollow actions : {0} unfollowed", unfollowDone);
            }
            else
            {
                _logger.LogDebug("Unfollow actions : {0}/{1} unfollowed (not all done, seem not any more user to unfollow)", unfollowDone, unfollowTodo);
            }

            // close the popup
            await _seleniumWrapper.Click(_instagramOptions.CssContactsClose);
        }