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()); }
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); }
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); }
public GetInfoGroup(IVkApiCategories api) { _api = api; }
public GetMembersByGroup(IVkApiCategories api) { _api = api; }
public IGetInfoGroup CreateGetInfoGroup(IVkApiCategories api) { return(new GetInfoGroup(api)); }
public IGetImages CreateGetImagesForGroups(IVkApiCategories api) { return(new GetImages(api)); }
public IGetMembersByGroup CreateGetMembersByGroup(IVkApiCategories api) { return(new GetMembersByGroup(api)); }
public IGetGroups CreateGetGroups(IVkApiCategories api) { return(new GetGroups(api)); }
public GetGroups(IVkApiCategories api) { _api = api; }
public GetImages(IVkApiCategories api) { _api = api; }