Esempio n. 1
0
        private async Task ProcessModLog()
        {
            var yt = new YouTubeService(new BaseClientService.Initializer {
                ApiKey = YouTubeAPIKey
            });

            var req            = yt.Videos.List("snippet");
            var lastRemoval    = PostRemoval.GetLastProcessedRemovalDate(Subreddit);
            var processedCount = 0;
            var modActions     = RedditClient.GetSubreddit(Subreddit).GetModerationLog(ModActionType.RemoveLink).GetListing(300, 100);
            var newPosts       = new Dictionary <string, List <UserPost> >();

            foreach (var modAct in modActions)
            {
                if (modAct.TimeStamp <= lastRemoval || processedCount > 100)
                {
                    break;                                                            //probably dumb and unnecessary
                }
                processedCount++;
                var post = RedditClient.GetThingByFullname(modAct.TargetThingFullname) as Post;

                var userPost = new UserPost();
                userPost.ThingID   = post.Id;
                userPost.Link      = post.Url.ToString();
                userPost.PostTime  = post.CreatedUTC;
                userPost.UserName  = post.AuthorName;
                userPost.Subreddit = Subreddit;

                var removal = new PostRemoval(modAct);
                removal.Post = userPost;

                var newPost = PostRemoval.AddRemoval(removal);
                if (newPost != null)
                {
                    var ytID = YouTubeHelpers.ExtractVideoId(post.Url.ToString());
                    if (!string.IsNullOrEmpty(ytID))
                    {
                        if (!newPosts.ContainsKey(ytID))
                        {
                            newPosts.Add(ytID, new List <UserPost>());
                        }
                        newPosts[ytID].Add(newPost);
                    }
                }

                if (processedCount % 75 == 0)
                {
                    await UpdateChannels(newPosts, req);

                    newPosts.Clear();
                }
            }

            await UpdateChannels(newPosts, req);
        }