Exemplo n.º 1
0
        private async Task <MediasResponse> GetLocationsMediaAsync()
        {
            var random    = new Random();
            var locations = new InstaSharp.Endpoints.Locations(ApiConfig);

            var location        = LocationsToProcess.ToArray()[random.Next(0, LocationsToProcess.Count() - 1)];
            var locationsResult = (await locations.Search(location.id, InstaSharp.Endpoints.Locations.FoursquareVersion.Two)).Data.FirstOrDefault();
            var mediaResult     = await locations.Recent(locationsResult.Id.ToString(), DateTime.Now - new TimeSpan(30, 0, 0, 0, 0), null, null, null);

            random    = null;
            locations = null;
            return(mediaResult);
        }
Exemplo n.º 2
0
        public override async Task <IEnumerable <RequestResult> > DoActionAsync(TimeSpan workPeriod, CancellationToken cancelToken, string commentText = null)
        {
            var tagsAvailable      = TagsToProcess != null && TagsToProcess.Count() != 0;
            var locationsAvailable = LocationsToProcess != null && LocationsToProcess.Count() != 0;

            if (!tagsAvailable && !locationsAvailable)
            {
                throw new InstAdException(InstAdErrors.NoTagsOrLocationsSpecified);
            }

            _currentActionResultsList = new ObservableCollection <RequestResult>();

            var start  = DateTime.Now;
            var end    = DateTime.Now.Add(workPeriod);
            var random = new Random();
            var isLike = string.IsNullOrWhiteSpace(commentText);

            if (UserId == 0)
            {
                await GetSeleniumUserId();
            }

            var waitSeconds     = 40; //todo: userSetting
            var likeFrequency   = 2;  //todo: userSetting // это типа каждое n-е фото только лайкает, чтоб никто ни о чём не догадался ]:->
            var banCount        = 0;
            var count           = 0;
            var banCountSetting = 10; //todo: userSettin
            var lastId          = await Task.Run(() => RequestService.GetAll()?.OrderByDescending(c => c.ModifyDate).Select(c => c.PostId)?.FirstOrDefault());

            var shouldObfuscate   = false;
            var obfuscator        = new SentenceObfuscator(commentText, DataStringService);
            var obfuscatorHistory = obfuscator.GetHistoryOfSentenceChanges();

            do
            {
                //var tag = TagsToProcess.ToArray()[random.Next(0, TagsToProcess.Count() - 1)];
                var result = random.Next(0, 1) == 0 && TagsToProcess.Count() != 0 ? (await GetTagsMediaAsync(lastId)) : (await GetLocationsMediaAsync());

                foreach (var res in result.Data.ToArray())
                {
                    if (cancelToken.IsCancellationRequested)
                    {
                        Finish(out lastId);
                        throw new InstAdException(InstAdErrors.OperationCancelled);
                    }

                    if (string.IsNullOrWhiteSpace(lastId))
                    {
                        lastId = GetCurrLastId();
                    }

                    var timer = random.Next(10, waitSeconds);
                    obfuscatorHistory = obfuscator.GetHistoryOfSentenceChanges();
                    if (random.Next(0, waitSeconds) <= waitSeconds / likeFrequency)
                    {
                        commentText     = shouldObfuscate ? obfuscator.Next() : obfuscatorHistory[random.Next(0, obfuscatorHistory.Count() - 1)];
                        shouldObfuscate = false;

                        var actionResult = await Task.Run(() => isLike?AddLike(res) : AddComment(res, commentText));

                        if (actionResult != null)
                        {
                            if (actionResult.VictimsId == 0)
                            {
                                count++;
                            }
                            else
                            {
                                _currentActionResultsList.Add(actionResult);
                            }
                        }
                        else
                        {
                            banCount++;
                            shouldObfuscate = true;
                            if (banCount == banCountSetting)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        count++;
                        WebDriver.Navigate().GoToUrl(res.Link);
                    }
                    if (DateTime.Now > end)
                    {
                        Finish(out lastId);
                        return(_currentActionResultsList.ToList());
                    }
                    await Task.Run(() => Thread.Sleep(new TimeSpan(0, 0, timer)));
                }

                lastId = result.Pagination.NextMaxTagId;
                SaveToDb();
            } while (DateTime.Now > end);

            return(_currentActionResultsList.ToList());
        }