コード例 #1
0
ファイル: Program.cs プロジェクト: sanbir/InstAd128k
        static void Main(string[] args)
        {
            LoadContainer();
            var srv = _container.Resolve <IDataStringService>();

            var senOb = new SentenceObfuscator("Привет, мамочка и папочка! Я курю сиги:\\)).", srv);

            for (var i = 0; i < 100; i++)
            {
                var next = senOb.Next();
            }
        }
コード例 #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());
        }
コード例 #3
0
ファイル: InstagramUser.cs プロジェクト: sanbir/InstAd128k
        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();
        }