Beispiel #1
0
        private static async Task <List <UserExtended> > GetUsersForBackgroundWork(List <CityExtended> cities,
                                                                                   List <long> blackListedUserIds, int?count = null)
        {
            var likeClickerUsers = await _likeClickerService.GetUserIdsByStrategyAsync(_strategy,
                                                                                       _groupNames, new AgeRange(17, 30), _cityIds,
                                                                                       MinDateForPostsBackGroundWork, blackListedUserIds);

            var res       = new List <UserExtended>();
            var cityNames = cities.Select(x => x.Title).Distinct().ToArray();

            likeClickerUsers = ExcludeDeletedUsers(likeClickerUsers);

            if (count.HasValue)
            {
                likeClickerUsers = likeClickerUsers.Take(count.Value).ToList();
            }

            foreach (var user in likeClickerUsers)
            {
                var friends = _userService.GetFriends(user.Id);

                System.Console.WriteLine($"Friends count for {user.GetDomainForUser()} is {friends.Count}");

                foreach (var friend in friends)
                {
                    if (!SatisfyBySecondAlgorithm(friend))
                    {
                        continue;
                    }

                    if (!friend.FromCity(cities))
                    {
                        continue;
                    }

                    res.Add(friend);
                }
            }

            res = res.Where(u => !blackListedUserIds.Contains(u.Id)).Select(x => x).ToList();
            return(res);
        }
Beispiel #2
0
        private static async Task Main()
        {
            var ps = Process.GetCurrentProcess();

            ps.PriorityClass = ProcessPriorityClass.RealTime;

            ServiceInjector.ConfigureServices();
            InjectServices();
            FillConfigurations();

            Console.Clear();
            Console.WriteLine("Get user ids...");

            var blackListedUserIds = _userService.GetBannedIds().Distinct().ToList();

            var filteredUsers = await _likeClickerService.GetUserIdsByStrategyAsync(_strategy,
                                                                                    _groupNames, new AgeRange(_minAge, _maxAge), _cityIds, MinDateForPosts, blackListedUserIds);

            using (var api = _apiFactory.CreateVkApi())
            {
                var counter = 0;
                var count   = filteredUsers.Count - 1;
                do
                {
                    if (!filteredUsers.Any())
                    {
                        break;
                    }

                    var user = filteredUsers[counter];

                    var wait = (counter % 2 > 0) ? 3 : 4;
                    if (user.Age % 2 > 0)
                    {
                        wait = (counter % 2 > 0) ? 2 : new Random().Next(1, 5);
                    }

                    try
                    {
                        var profilePhotos = _photoService.GetProfilePhotos(user.Id);
                        var skip          = SkipRecentlyLiked(profilePhotos);
                        var result        = false;

                        if (!skip)
                        {
                            result = LikeProfilePhotos(profilePhotos, api, user);
                        }

                        counter++;

                        var message =
                            $"vk.com/{user.Domain} - {(result ? "liked" : "passed")}.{Environment.NewLine}Last activity date: {user.LastActivityDate}, age: {user.Age}, has child: {user.HasChildrens.ToString().ToLower()}.{Environment.NewLine}Time {DateTime.Now}. {counter} out of {count}";

                        Console.WriteLine(message);

                        if (result)
                        {
                            api.Account.SetOffline();
                            System.Threading.Thread.Sleep(TimeSpan.FromMinutes(wait));
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Exception:" + e.Message);
                        System.Threading.Thread.Sleep(TimeSpan.FromMinutes(5));
                    }
                } while (counter < count);
            }

            Console.ReadLine();
        }