Esempio n. 1
0
        public async Task <int> RemoveSubscribersAsync(int count)
        {
            if (!_api.IsUserAuthenticated)
            {
                await _api.LoginAsync();
            }

            var type = _api.GetType();

            type.GetProperty("IsUserAuthenticated")?.SetValue(_api, true);

            var currentUser = await _api.GetCurrentUserAsync();

            var followings = await _api.GetUserFollowingAsync(currentUser.Value.UserName, PaginationParameters.MaxPagesToLoad(20));

            var iteration = 0;

            foreach (var following in followings.Value)
            {
                if (iteration == count)
                {
                    return(iteration);
                }

                await Task.Delay(TimeSpan.FromMilliseconds(new Random().Next(20, 200)));

                var unFollowResult = await _api.UnFollowUserAsync(following.Pk);

                Console.WriteLine($"{(unFollowResult.Succeeded ? $"Success unfollowed {following.UserName}" : unFollowResult.Info.Message)}");

                iteration++;
            }

            return(iteration);
        }
        private async Task <IndexModel> GetData(string username)
        {
            var model = new IndexModel();

            model.Username = username;

            var followers = await _instaApi.GetUserFollowersAsync(username, PaginationParameters.Empty);

            var following = await _instaApi.GetUserFollowingAsync(username, PaginationParameters.Empty);

            if (!followers.Succeeded || !following.Succeeded)
            {
                model.Message = "User not found.";
                return(model);
            }

            model.Followers = followers.Value.ToList();
            model.Following = following.Value.ToList();

            model.FollowersNotFollowed  = model.Followers.Where(x => model.Following.All(y => y.UserName != x.UserName)).ToList();
            model.FollowingNotFollowers = model.Following.Where(x => model.Followers.All(y => y.UserName != x.UserName)).ToList();

            model.SearchedWithSuccess = true;

            return(model);
        }
Esempio n. 3
0
        public static async Task <InstaUserShortList> GetFollowingList(IInstaApi api)
        {
            var following = await api.GetUserFollowingAsync(user.UserName, PaginationParameters.Empty);

            var followingList = following.Value;

            return(followingList);
        }
Esempio n. 4
0
        public async Task <List <UserInfo> > GetCurrentUserFollowings(int maxPageToLoad = 10)
        {
            validateInstaClient();
            validateLoggedIn();

            IResult <InstaUserShortList> userShortList = await instaApi.GetUserFollowingAsync(user.UserName, PaginationParameters.MaxPagesToLoad(maxPageToLoad));

            return(userShortList.Value.ToUserInfoList());
        }
        private static async Task <InstaUserShortList> GetFollowingList(IInstaApi api, string username)
        {
            var following = await api.GetUserFollowingAsync(username, PaginationParameters.Empty);

            if (following.Info.ResponseType != ResponseType.OK && following.Info.Exception.Message == "Object reference not set to an instance of an object.")
            {
                throw new Exception("Please Check Your Username!");
            }

            var followingList = following.Value;

            return(followingList);
        }
Esempio n. 6
0
        public async Task <MainLoginModel> UpdateLoginModel()
        {
            var info = await _instaApi.GetCurrentUserAsync();

            var model = new MainLoginModel {
                CurrentUser = info.Value
            };

            var followers =
                await _instaApi.GetUserFollowersAsync(info.Value.UserName, PaginationParameters.MaxPagesToLoad(15));

            model.Followers = followers.Value;
            var following = await _instaApi.GetUserFollowingAsync(info.Value.UserName, PaginationParameters.MaxPagesToLoad(15));

            model.Following = following.Value;
            return(model);
        }
Esempio n. 7
0
        /// <summary>
        /// Get All the following list of logged in user
        /// </summary>
        /// <returns>The following list</returns>
        public async Task <IResult <InstaUserShortList> > GetFollowing()
        {
            IResult <InstaUserShortList> following = await api.GetUserFollowingAsync(user.UserName, PaginationParameters.Empty);

            return(following);
        }
Esempio n. 8
0
        async void UnSubscribeDontFollow(IInstaApi api, SettingTaskUnSubscribe setting)
        {
            userInfoLog = await api.GetCurrentUserAsync();

            var follow = await api.GetCurrentUserFollowersAsync(PaginationParameters.MaxPagesToLoad(2));

            var x = await api.GetUserFollowingAsync(userInfoLog.Value.UserName, PaginationParameters.MaxPagesToLoad(2));

            var z = await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk);

            EventUpdateGrid(this, new UpdateGridEvent(
                                $"{userInfoLog.Value.UserName}:Отписка(кто не подписан):{CountUnSubscribe}/{z.Value.FollowingCount}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" +
                                $"Выполняется"));
            EventFromMyClass(this, new MyEventMessage($"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Массотписка запущена"));

            foreach (InstaUserShort user in x.Value)
            {
                try
                {
                    if (_source == null || _source.IsCancellationRequested)
                    {
                        break;
                    }


                    if (setting.FileNameBaseId != null && setting.FileNameDontUnSubscribeId.Length != 0) //Учет не отписки от определнных пользователей
                    {
                        var stringId = setting.FileNameDontUnSubscribeId.Split(' ');
                        foreach (string id in stringId)
                        {
                            if (user.Pk == Convert.ToInt64(id))
                            {
                                EventFromMyClass(this, new MyEventMessage($"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Пропущен пользователь {user.UserName}. Является исключением"));
                                Delay();
                                continue;
                            }
                        }
                    }
                    var userShort = new InstaUserShort();
                    userShort.Pk = user.Pk;

                    if (follow.Value.IndexOf(userShort) == -1)
                    {
                        if (setting.ChekedUnSubscribeBlock) //Учёт отписки через блокировку
                        {
                            await api.BlockUserAsync(user.Pk);
                        }
                        else
                        {
                            await api.UnFollowUserAsync(user.Pk);
                        }
                        CountUnSubscribe++;
                        CountPause++;
                        EventFromMyClass(this, new MyEventMessage($"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Отписался от пользователя с ником: {user.UserName}. Kоличество отписок: {CountUnSubscribe}"));
                        EventUpdateGrid(this, new UpdateGridEvent(
                                            $"{userInfoLog.Value.UserName}:Отписка(кто не подписан):{CountUnSubscribe}/{z.Value.FollowingCount}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" +
                                            $"Выполняется"));

                        if (_source == null || _source.IsCancellationRequested)
                        {
                            break;
                        }

                        Delay();                                          // Учет задержки

                        if (CountUnSubscribe >= setting.LimitUnSubscribe) //Учет лимита отписок
                        {
                            EventFromMyClass(this, new MyEventMessage($"[{userInfoLog.Value.UserName}][{ DateTime.Now.ToString("HH:mm:ss") }] Превышен лимит подписок"));
                            EventUpdateGrid(this, new UpdateGridEvent(
                                                $"{userInfoLog.Value.UserName}:Отписка(кто не подписан):{CountUnSubscribe}/{z.Value.FollowingCount}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" +
                                                $"Завершено"));
                            return;
                        }

                        if (setting.CheckedPause) //Учет паузы
                        {
                            if (setting.PauseLimit <= CountUnSubscribe)
                            {
                                CountPause = 0;
                                EventUpdateGrid(this, new UpdateGridEvent(
                                                    $"{userInfoLog.Value.UserName}:Отписка(кто не подписан):{CountUnSubscribe}/{z.Value.FollowingCount}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" +
                                                    $"Пауза"));
                                EventFromMyClass(this, new MyEventMessage($"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Пауза на " + setting.PauseTime + " минут"));
                                if (timer != null)
                                {
                                    timer.Dispose();
                                }
                                timer = new Timer(CancelDelay, null, 60000 * setting.PauseTime, Timeout.Infinite);
                                ew.Reset();
                                ew.WaitOne();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    EventFromMyClass(this, new MyEventMessage($"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] ОШИБКА: {e.Message}"));
                }
            }
            EventFromMyClass(this, new MyEventMessage($"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Выполнено"));
            EventUpdateGrid(this, new UpdateGridEvent(
                                $"{userInfoLog.Value.UserName}:Отписка(кто не подписан):{CountUnSubscribe}/{z.Value.FollowingCount}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" +
                                $"Завершено"));
            Stat = false;
        }
Esempio n. 9
0
        async void Sbor()
        {
            info.File   = setting.SborAcc_SaveFileName;
            info.Status = "Выполняется";
            int progress = 0;

            info.Progress = $"{progress}/{setting.SborAcc_CountOneUser * setting.SborAcc_ListUserNames.Count}";
            EventUpdateGrid(this, new UpdateGridAudience(info));

            foreach (string username in setting.SborAcc_ListUserNames)
            {
                if (_source == null || _source.IsCancellationRequested)
                {
                    break;
                }
                int maxPagesToLoad = setting.SborAcc_CountOneUser % 200 == 0
                    ? setting.SborAcc_CountOneUser / 200
                    : (setting.SborAcc_CountOneUser / 200) + 1;
                if (setting.SborAcc_Sbor == Audience.Sbor.Followers)
                {
                    var infoFollowers =
                        await api.GetUserFollowersAsync(username, PaginationParameters.MaxPagesToLoad(maxPagesToLoad));

                    ew.WaitOne();
                    info.Status = "Выполняется";
                    if (infoFollowers.Value.Count != 0 || infoFollowers.Succeeded)
                    {
                        for (int i = 0; i < infoFollowers.Value.Count; i++)
                        {
                            try
                            {
                                if (_source == null || _source.IsCancellationRequested)
                                {
                                    break;
                                }

                                if (i > setting.SborAcc_CountOneUser)
                                {
                                    break;
                                }
                                if (WhatAccPars.onlyPrivate == setting.SborAcc_WhatAccPars &&
                                    !infoFollowers.Value[i].IsPrivate)
                                {
                                    continue;
                                }
                                if (WhatAccPars.onlyPrivate == setting.SborAcc_WhatAccPars &&
                                    infoFollowers.Value[i].IsPrivate)
                                {
                                    if (setting.SborAcc_WhatPars == WhatPars.ID)
                                    {
                                        listAcc.Add(infoFollowers.Value[i].Pk.ToString());
                                    }

                                    if (setting.SborAcc_WhatPars == WhatPars.Login)
                                    {
                                        listAcc.Add(infoFollowers.Value[i].UserName);
                                    }
                                }

                                if (WhatAccPars.onlyPublic == setting.SborAcc_WhatAccPars &&
                                    infoFollowers.Value[i].IsPrivate)
                                {
                                    continue;
                                }
                                if (WhatAccPars.onlyPublic == setting.SborAcc_WhatAccPars &&
                                    !infoFollowers.Value[i].IsPrivate)
                                {
                                    if (setting.SborAcc_WhatPars == WhatPars.ID)
                                    {
                                        listAcc.Add(infoFollowers.Value[i].Pk.ToString());
                                    }

                                    if (setting.SborAcc_WhatPars == WhatPars.Login)
                                    {
                                        listAcc.Add(infoFollowers.Value[i].UserName);
                                    }
                                }

                                if (WhatAccPars.All == setting.SborAcc_WhatAccPars)
                                {
                                    if (setting.SborAcc_WhatPars == WhatPars.ID)
                                    {
                                        listAcc.Add(infoFollowers.Value[i].Pk.ToString());
                                    }

                                    if (setting.SborAcc_WhatPars == WhatPars.Login)
                                    {
                                        listAcc.Add(infoFollowers.Value[i].UserName);
                                    }
                                }

                                progress++;
                                info.Progress =
                                    $"{progress}/{setting.SborAcc_CountOneUser * setting.SborAcc_ListUserNames.Count}";
                                EventUpdateGrid(this, new UpdateGridAudience(info));
                            }
                            catch
                            {
                                continue;
                            }
                        }
                    }
                }
                else
                {
                    var infoFollowers =
                        await api.GetUserFollowingAsync(username, PaginationParameters.MaxPagesToLoad(maxPagesToLoad));

                    ew.WaitOne();
                    info.Status = "Выполняется";
                    if (infoFollowers.Succeeded || infoFollowers.Value.Count != 0)
                    {
                        for (int i = 0; i < infoFollowers.Value.Count; i++)
                        {
                            try
                            {
                                if (_source == null || _source.IsCancellationRequested)
                                {
                                    break;
                                }
                                if (i > setting.SborAcc_CountOneUser)
                                {
                                    break;
                                }
                                if (WhatAccPars.onlyPrivate == setting.SborAcc_WhatAccPars &&
                                    !infoFollowers.Value[i].IsPrivate)
                                {
                                    continue;
                                }
                                if (WhatAccPars.onlyPrivate == setting.SborAcc_WhatAccPars &&
                                    infoFollowers.Value[i].IsPrivate)
                                {
                                    if (setting.SborAcc_WhatPars == WhatPars.ID)
                                    {
                                        listAcc.Add(infoFollowers.Value[i].Pk.ToString());
                                    }

                                    if (setting.SborAcc_WhatPars == WhatPars.Login)
                                    {
                                        listAcc.Add(infoFollowers.Value[i].UserName);
                                    }
                                }

                                if (WhatAccPars.onlyPublic == setting.SborAcc_WhatAccPars &&
                                    infoFollowers.Value[i].IsPrivate)
                                {
                                    continue;
                                }
                                if (WhatAccPars.onlyPublic == setting.SborAcc_WhatAccPars &&
                                    !infoFollowers.Value[i].IsPrivate)
                                {
                                    if (setting.SborAcc_WhatPars == WhatPars.ID)
                                    {
                                        listAcc.Add(infoFollowers.Value[i].Pk.ToString());
                                    }

                                    if (setting.SborAcc_WhatPars == WhatPars.Login)
                                    {
                                        listAcc.Add(infoFollowers.Value[i].UserName);
                                    }
                                }

                                if (WhatAccPars.All == setting.SborAcc_WhatAccPars)
                                {
                                    if (setting.SborAcc_WhatPars == WhatPars.ID)
                                    {
                                        listAcc.Add(infoFollowers.Value[i].Pk.ToString());
                                    }

                                    if (setting.SborAcc_WhatPars == WhatPars.Login)
                                    {
                                        listAcc.Add(infoFollowers.Value[i].UserName);
                                    }
                                }

                                progress++;
                                info.Progress =
                                    $"{progress}/{setting.SborAcc_CountOneUser * setting.SborAcc_ListUserNames.Count}";
                                EventUpdateGrid(this, new UpdateGridAudience(info));
                            }
                            catch
                            {
                                continue;
                            }
                        }
                    }
                }
                Thread.Sleep(5000);
            }
            Save();
            info.Status = "Выполнено";
            EventUpdateGrid(this, new UpdateGridAudience(info));
        }
Esempio n. 10
0
        public async Task DoShow()
        {
            // get currently logged in user
            var currentUser = await _instaApi.GetCurrentUserAsync();

            Console.WriteLine(
                $"Logged in: username - {currentUser.Value.UserName}, full name - {currentUser.Value.FullName}");

            // get self followers
            var followers = await _instaApi.GetUserFollowersAsync(currentUser.Value.UserName, 5);

            Console.WriteLine($"Count of followers [{currentUser.Value.UserName}]:{followers.Value.Count}");

            // get self folling
            var following = await _instaApi.GetUserFollowingAsync(currentUser.Value.UserName, 5);

            Console.WriteLine($"Count of following [{currentUser.Value.UserName}]:{following.Value.Count}");

            // get self user's media, latest 5 pages
            var currentUserMedia = await _instaApi.GetUserMediaAsync(currentUser.Value.UserName, 5);

            if (currentUserMedia.Succeeded)
            {
                Console.WriteLine($"Media count [{currentUser.Value.UserName}]: {currentUserMedia.Value.Count}");
                foreach (var media in currentUserMedia.Value)
                {
                    ConsoleUtils.PrintMedia("Self media", media, _maxDescriptionLength);
                }
            }

            //get user time line feed, latest 5 pages
            var userFeed = await _instaApi.GetUserTimelineFeedAsync(5);

            if (userFeed.Succeeded)
            {
                Console.WriteLine(
                    $"Feed items (in {userFeed.Value.MediaItemsCount} pages) [{currentUser.Value.UserName}]: {userFeed.Value.Medias.Count}");
                foreach (var media in userFeed.Value.Medias)
                {
                    ConsoleUtils.PrintMedia("Feed media", media, _maxDescriptionLength);
                }
                //like first 10 medias from user timeline feed
                foreach (var media in userFeed.Value.Medias.Take(10))
                {
                    var likeResult = await _instaApi.LikeMediaAsync(media.InstaIdentifier);

                    var resultString = likeResult.Value ? "liked" : "not liked";
                    Console.WriteLine($"Media {media.Code} {resultString}");
                }
            }

            // get tag feed, latest 5 pages
            var tagFeed = await _instaApi.GetTagFeedAsync("quadcopter", 5);

            if (tagFeed.Succeeded)
            {
                Console.WriteLine(
                    $"Tag feed items (in {tagFeed.Value.MediaItemsCount} pages) [{currentUser.Value.UserName}]: {tagFeed.Value.Medias.Count}");
                foreach (var media in tagFeed.Value.Medias)
                {
                    ConsoleUtils.PrintMedia("Tag feed", media, _maxDescriptionLength);
                }
            }
        }
Esempio n. 11
0
        async void ClearBots()
        {
            Stat        = true;
            userInfoLog = await api.GetCurrentUserAsync();

            EventFromMyClass(this, new MyEventMessage($"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Чистка от ботов запущена"));
            try
            {
                if (setting.FileNameExceptionId.Length != 0)
                {
                    string[] stringID = System.IO.File.ReadAllLines(setting.FileNameExceptionId);
                    foreach (string str in stringID)
                    {
                        try
                        {
                            usersID.Add(Convert.ToInt64(str));
                        }
                        catch { continue; }
                    }
                }
            }
            catch (Exception e)
            {
                EventFromMyClass(this, new MyEventMessage($"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] ОШИБКА: {e.Message}"));
            }

            var userInfo = await api.GetCurrentUserAsync();

            IResult <InstaUserShortList> x = null;

            if (setting.WhomClear.Equals("Подписчиков"))
            {
                x = await api.GetUserFollowersAsync(userInfo.Value.UserName, PaginationParameters.MaxPagesToLoad(2));
            }
            if (setting.WhomClear.Equals("Подписки"))
            {
                x = await api.GetUserFollowingAsync(userInfo.Value.UserName, PaginationParameters.MaxPagesToLoad(2));
            }
            if (x.Succeeded)
            {
                count = x.Value.Count;
                EventUpdateGrid(this, new UpdateGridEvent(
                                    $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" +
                                    $"Выполняется"));

                foreach (InstaUserShort user in x.Value)
                {
                    try
                    {
                        if (_source == null || _source.IsCancellationRequested)
                        {
                            break;
                        }


                        if (usersID.Count != 0) //Учет не отписки от определнных пользователей
                        {
                            bool flag = false;
                            foreach (long id in usersID)
                            {
                                if (user.Pk == id)
                                {
                                    EventFromMyClass(this,
                                                     new MyEventMessage(
                                                         $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Пользователь {user.UserName} пропущен. Запрет на отписку."));

                                    Delay();

                                    flag = true;
                                    break;
                                }
                            }

                            if (flag)
                            {
                                continue;
                            }
                        }

                        if (setting.LimitBlock <= CountBlock) //Учет лимита блокировок
                        {
                            EventFromMyClass(this,
                                             new MyEventMessage(
                                                 $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Превышен лимит блокировок. Останавливаю процесс."));
                            EventUpdateGrid(this, new UpdateGridEvent(
                                                $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" +
                                                $"Завершено"));
                            return;
                        }

                        if (setting.ChekedPause) //Учет паузы
                        {
                            if (setting.PauseLimit <= CountPause)
                            {
                                CountPause = 0;
                                EventFromMyClass(this,
                                                 new MyEventMessage(
                                                     $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Пауза на " +
                                                     setting.PauseTime + " минут"));
                                EventUpdateGrid(this, new UpdateGridEvent(
                                                    $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" +
                                                    $"Пауза"));
                                if (timer != null)
                                {
                                    timer.Dispose();
                                }
                                timer = new Timer(CancelDelay, null, 60000 * (int)setting.PauseTime, Timeout.Infinite);
                                ew.Reset();
                                ew.WaitOne();
                            }
                        }


                        var info = await api.GetUserInfoByIdAsync(user.Pk);

                        if (info.Succeeded == false)
                        {
                            Thread.Sleep(500);
                            continue;
                        }

                        if (setting.CheckedNoAvatarUser) //Если нет автарки
                        {
                            if (info.Value.HasAnonymousProfilePicture)
                            {
                                await api.BlockUserAsync(user.Pk);

                                CountBlock++;
                                CountPause++;
                                EventFromMyClass(this,
                                                 new MyEventMessage(
                                                     $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Заблокирован пользователя с ником: {user.UserName}. Количество блокировок: {CountBlock}"));
                                EventUpdateGrid(this, new UpdateGridEvent(
                                                    $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" +
                                                    $"Выполняется"));

                                if (!setting.ChekedUserBlock)
                                {
                                    await api.UnBlockUserAsync(user.Pk);

                                    EventFromMyClass(this,
                                                     new MyEventMessage(
                                                         $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Разблокирован пользователь с ником: {user.UserName}"));
                                }

                                Delay(); //Учет задержки
                                continue;
                            }
                        }

                        if (setting.CheckedPublicCountLess) //Публикаций меньше
                        {
                            int countPublic = Convert.ToInt32(info.Value.MediaCount);
                            if (countPublic < setting.PublicCountLess)
                            {
                                await api.BlockUserAsync(user.Pk);

                                CountBlock++;
                                CountPause++;
                                EventFromMyClass(this,
                                                 new MyEventMessage(
                                                     $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Заблокирован пользователь с ником: {user.UserName}. Количество блокировок: {CountBlock}"));
                                EventUpdateGrid(this, new UpdateGridEvent(
                                                    $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" +
                                                    $"Выполняется"));
                                if (!setting.ChekedUserBlock)
                                {
                                    await api.UnBlockUserAsync(user.Pk);

                                    EventFromMyClass(this,
                                                     new MyEventMessage(
                                                         $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Разблокирован пользователь с ником: {user.UserName}"));
                                }

                                Delay(); //Учет задержки
                                continue;
                            }
                        }

                        if (setting.ChekedFollowsCountLess)
                        {
                            int countFollower = Convert.ToInt32(info.Value.FollowerCount);
                            if (countFollower < setting.FollowsCountLess)
                            {
                                await api.BlockUserAsync(user.Pk);

                                CountBlock++;
                                CountPause++;
                                EventFromMyClass(this,
                                                 new MyEventMessage(
                                                     $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Заблокирован пользователь с ником: {user.UserName}. Количество блокировок: {CountBlock}"));
                                EventUpdateGrid(this, new UpdateGridEvent(
                                                    $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" +
                                                    $"Выполняется"));
                                if (!setting.ChekedUserBlock)
                                {
                                    await api.UnBlockUserAsync(user.Pk);

                                    EventFromMyClass(this,
                                                     new MyEventMessage(
                                                         $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Разблокирован пользователь с ником: {user.UserName}"));
                                }

                                Delay(); //Учет задержки
                                continue;
                            }
                        }

                        if (setting.ChekedSubscriptionsLess)
                        {
                            int countSubscriptions = Convert.ToInt32(info.Value.FollowingCount);
                            if (countSubscriptions < setting.SubscriptionsLess)
                            {
                                await api.BlockUserAsync(user.Pk);

                                CountBlock++;
                                CountPause++;
                                EventFromMyClass(this,
                                                 new MyEventMessage(
                                                     $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Заблокирован пользователь с ником: {user.UserName}. Количество блокировок: {CountBlock}"));
                                EventUpdateGrid(this, new UpdateGridEvent(
                                                    $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" +
                                                    $"Выполняется"));
                                if (!setting.ChekedUserBlock)
                                {
                                    await api.UnBlockUserAsync(user.Pk);

                                    EventFromMyClass(this,
                                                     new MyEventMessage(
                                                         $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Разблокирован пользователь с ником: {user.UserName}"));
                                }

                                Delay(); //Учет задержки
                                continue;
                            }
                        }

                        if (setting.ChekedSubscriptionsMore)
                        {
                            int countSubscriptions = Convert.ToInt32(info.Value.FollowingCount);
                            if (countSubscriptions > setting.SubscriptionMore)
                            {
                                await api.BlockUserAsync(user.Pk);

                                CountBlock++;
                                CountPause++;
                                EventFromMyClass(this,
                                                 new MyEventMessage(
                                                     $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Заблокирован пользователь с ником: {user.UserName}. Количество блокировок: {CountBlock}"));
                                EventUpdateGrid(this, new UpdateGridEvent(
                                                    $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" +
                                                    $"Выполняется"));
                                if (!setting.ChekedUserBlock)
                                {
                                    await api.UnBlockUserAsync(user.Pk);

                                    EventFromMyClass(this,
                                                     new MyEventMessage(
                                                         $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] Разблокирован пользователь с ником: {user.UserName}"));
                                }

                                Delay(); //Учет задержки
                                continue;
                            }
                        }

                        Thread.Sleep(1000);
                    }

                    catch (Exception e)
                    {
                        EventFromMyClass(this,
                                         new MyEventMessage(
                                             $"[{userInfoLog.Value.UserName}][{DateTime.Now.ToString("HH:mm:ss")}] ОШИБКА: {e.Message}"));
                    }
                }
            }

            EventFromMyClass(this, new MyEventMessage($"[{userInfoLog.Value.UserName}][{ DateTime.Now.ToString("HH:mm:ss")}] Выполнено."));
            EventUpdateGrid(this, new UpdateGridEvent(
                                $"{userInfoLog.Value.UserName}:Чистка от ботов:{CountBlock}/{x.Value.Count}:{UpdateInfoUser(await api.GetUserInfoByIdAsync(userInfoLog.Value.Pk))}:" +
                                $"Завершено"));
            Stat = false;
        }
Esempio n. 12
0
        public static async Task <bool> MainAsync()
        {
            var binFolder = configFile.AppSettings.Settings["BinFolder"].Value;

            Directory.CreateDirectory(binFolder);

            var hardFollows    = configFile.AppSettings.Settings["HardFollows"].Value;
            var hardFollowList = hardFollows.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();

            var userSession = new UserSessionData
            {
                UserName = configFile.AppSettings.Settings["UserName"].Value,
                Password = configFile.AppSettings.Settings["Password"].Value
            };
            var delay = RequestDelay.FromSeconds(2, 2);

            _instaApi = InstaApiBuilder.CreateBuilder().SetUser(userSession).SetRequestDelay(delay).Build();

            var stateFilePath = binFolder + stateFile;

            try
            {
                if (File.Exists(stateFilePath))
                {
                    //Console.WriteLine("Loading state from file");
                    using (var fs = File.OpenRead(stateFilePath))
                    {
                        _instaApi.LoadStateDataFromStream(fs);
                    }
                }
            }
            catch (Exception e)
            {
                return(false);
            }

            if (!_instaApi.IsUserAuthenticated)
            {
                //Console.WriteLine($"Logging in as {userSession.UserName}");
                delay.Disable();
                var logInResult = await _instaApi.LoginAsync();

                delay.Enable();
                if (!logInResult.Succeeded)
                {
                    //Console.WriteLine($"Unable to login: {logInResult.Info.Message}");
                    return(false);
                }
            }
            var state = _instaApi.GetStateDataAsStream();

            using (var fileStream = File.Create(stateFilePath))
            {
                state.Seek(0, SeekOrigin.Begin);
                state.CopyTo(fileStream);
            }

            var currentUser = await _instaApi.GetCurrentUserAsync();

            //Console.WriteLine($"Logged in: username - {currentUser.Value.UserName}, full name - {currentUser.Value.FullName}");
            //var followers = await _instaApi.GetCurrentUserFollowersAsync(PaginationParameters.MaxPagesToLoad(6));
            //Console.WriteLine($"Count of followers [{currentUser.Value.UserName}]:{followers.Value.Count}");

            var followers = await _instaApi.GetUserFollowersAsync(currentUser.Value.UserName, PaginationParameters.MaxPagesToLoad(6));

            var followersList = followers.Value.Select(p => p.UserName).ToList();

            var followersListPath = binFolder + @"FollowersLists\";

            Directory.CreateDirectory(followersListPath);
            var followerListFileFullName = followersListPath + "followersList" + now.ToString("yyyyMMddHHmmssFFFFFFF") + ".txt";

            File.WriteAllLines(followerListFileFullName, followersList);


            var following = await _instaApi.GetUserFollowingAsync(currentUser.Value.UserName, PaginationParameters.MaxPagesToLoad(6));

            var followingList     = following.Value.Select(p => p.UserName).ToList();
            var followingListPath = binFolder + @"FollowingLists\";

            Directory.CreateDirectory(followingListPath);
            var followingListFileFullName = followingListPath + "followingList" + now.ToString("yyyyMMddHHmmssFFFFFFF") + ".txt";

            File.WriteAllLines(followingListFileFullName, followingList);

            var msgBody = PrepareMsgBody(followingListPath, followersListPath);

            if (msgBody != string.Empty)
            {
                var subject = "Analiz! InstagramLooker - " + now.ToString("dd/MM/yyyy - HH:mm");
                SendMail(subject, msgBody);
            }

            DeleteOldestFile(followersListPath);
            DeleteOldestFile(followingListPath);

            //Console.WriteLine($"Count of following [{currentUser.Value.UserName}]:{following.Value.Count}");

            return(true);
        }
Esempio n. 13
0
        public async Task DoShow()
        {
            // get currently logged in user
            var currentUser = await _instaApi.GetCurrentUserAsync();

            Console.WriteLine(
                $"Logged in: username - {currentUser.Value.UserName}, full name - {currentUser.Value.FullName}");

            // get followers of user 'elonmusk'
            var followers = await _instaApi.GetUserFollowersAsync("elonmusk",
                                                                  PaginationParameters.MaxPagesToLoad(5)
                                                                  .StartFromId("AQAC8w90POWyM7zMjHWmO9vsZNL_TuLp6FR506_C_y3fUAjlCclrIDI2RdSGvur5UjLrq4Cq7NJN8QUhHG-vpbT6pCLB5X9crDxBOHUEuNJ4fA"));

            Console.WriteLine($"Count of followers [elonmusk]:{followers.Value.Count}");
            Console.WriteLine($"Next id will be: '{followers.Value.NextId}'");

            // get self folling
            var following = await _instaApi.GetUserFollowingAsync(currentUser.Value.UserName, PaginationParameters.MaxPagesToLoad(5));

            Console.WriteLine($"Count of following [{currentUser.Value.UserName}]:{following.Value.Count}");

            // get self user's media, latest 5 pages
            var currentUserMedia = await _instaApi.GetUserMediaAsync(currentUser.Value.UserName, PaginationParameters.MaxPagesToLoad(5));

            if (currentUserMedia.Succeeded)
            {
                Console.WriteLine($"Media count [{currentUser.Value.UserName}]: {currentUserMedia.Value.Count}");
                foreach (var media in currentUserMedia.Value)
                {
                    ConsoleUtils.PrintMedia("Self media", media, _maxDescriptionLength);
                }
            }

            //get user time line feed, latest 5 pages
            var userFeed = await _instaApi.GetUserTimelineFeedAsync(PaginationParameters.MaxPagesToLoad(5));

            if (userFeed.Succeeded)
            {
                Console.WriteLine(
                    $"Feed items (in {userFeed.Value.MediaItemsCount} pages) [{currentUser.Value.UserName}]: {userFeed.Value.Medias.Count}");
                foreach (var media in userFeed.Value.Medias)
                {
                    ConsoleUtils.PrintMedia("Feed media", media, _maxDescriptionLength);
                }
                //like first 10 medias from user timeline feed
                foreach (var media in userFeed.Value.Medias.Take(10))
                {
                    var likeResult = await _instaApi.LikeMediaAsync(media.InstaIdentifier);

                    var resultString = likeResult.Value ? "liked" : "not liked";
                    Console.WriteLine($"Media {media.Code} {resultString}");
                }
            }

            // get tag feed, latest 5 pages
            var tagFeed = await _instaApi.GetTagFeedAsync("quadcopter", PaginationParameters.MaxPagesToLoad(5));

            if (tagFeed.Succeeded)
            {
                Console.WriteLine(
                    $"Tag feed items (in {tagFeed.Value.MediaItemsCount} pages) [{currentUser.Value.UserName}]: {tagFeed.Value.Medias.Count}");
                foreach (var media in tagFeed.Value.Medias)
                {
                    ConsoleUtils.PrintMedia("Tag feed", media, _maxDescriptionLength);
                }
            }
        }