Exemplo n.º 1
0
        private static IEnumerable <long> GetLikesSegment(IVkApiCategories vk, string uri, uint index = 0)
        {
            var ids = GetPostIds(uri);

            if (!ids.Any())
            {
                return(new List <long>(1));
            }

            return(vk.Likes.GetList(new LikesGetListParams
            {
                Type = LikeObjectType.Post,
                Filter = LikesFilter.Likes,
                OwnerId = ids[0],
                ItemId = ids[1],
                Extended = false,
                Offset = index,
                Count = 1000
            }).ToList());
        }
Exemplo n.º 2
0
        private List <Post> GetLastPosts(IVkApiCategories api, long ownerId, int lastDays)
        {
            var       result   = new List <Post>();
            const int count    = 30;
            ulong     offset   = 0;
            var       stopFlag = false;

            while (!stopFlag)
            {
                var wall = api.Wall.Get(new WallGetParams()
                {
                    Count   = count,
                    Offset  = offset,
                    OwnerId = ownerId
                });
                if (wall.WallPosts.Count > 0)
                {
                    foreach (var post in wall.WallPosts)
                    {
                        if (post.Date?.Date.AddDays(lastDays) >= DateTime.Now.Date || post.IsPinned == true)
                        {
                            result.Add(post);
                        }
                        else
                        {
                            stopFlag = true;
                            break;
                        }
                    }

                    offset += count;
                }
                else
                {
                    break;
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        public IEnumerable <KeyValuePair <long, int> > GetTopLikers(IVkApiCategories api, long ownerId, int lastDays = 7)
        {
            var posts = GetLastPosts(api, ownerId, lastDays);

            _logger.LogTrace("Получено {PostCount} постов за {Day} дней.", posts.Count, lastDays);
            var likers = new List <long>();

            while (posts.Count > 0)
            {
                var postsIds      = posts.Take(MaxCallsInExecute).Select(x => x.Id);
                var executeScript = CreateExecuteScript(ownerId, postsIds);

                var response = api.Execute.Execute <List <VkCollection <long> > >(executeScript);
                foreach (var post in response)
                {
                    likers.AddRange(post);
                }

                posts = posts.Skip(MaxCallsInExecute).ToList();
            }

            var table = new Dictionary <long, int>();

            foreach (var liker in likers)
            {
                if (!table.ContainsKey(liker))
                {
                    table[liker] = 0;
                }

                table[liker]++;
            }

            var topLikers = table.ToList();

            topLikers.Sort((p1, p2) => p2.Value.CompareTo(p1.Value));
            return(topLikers);
        }
Exemplo n.º 4
0
 public GetInfoGroup(IVkApiCategories api)
 {
     _api = api;
 }
Exemplo n.º 5
0
 public GetMembersByGroup(IVkApiCategories api)
 {
     _api = api;
 }
Exemplo n.º 6
0
 public IGetInfoGroup CreateGetInfoGroup(IVkApiCategories api)
 {
     return(new GetInfoGroup(api));
 }
Exemplo n.º 7
0
 public IGetImages CreateGetImagesForGroups(IVkApiCategories api)
 {
     return(new GetImages(api));
 }
Exemplo n.º 8
0
 public IGetMembersByGroup CreateGetMembersByGroup(IVkApiCategories api)
 {
     return(new GetMembersByGroup(api));
 }
Exemplo n.º 9
0
 public IGetGroups CreateGetGroups(IVkApiCategories api)
 {
     return(new GetGroups(api));
 }
Exemplo n.º 10
0
 public GetGroups(IVkApiCategories api)
 {
     _api = api;
 }
Exemplo n.º 11
0
 public GetImages(IVkApiCategories api)
 {
     _api = api;
 }