コード例 #1
0
ファイル: UserPost.cs プロジェクト: CrustyJew/DirtBag
 public static void InsertPost( UserPost post )
 {
     if ( post.Link.Length > 200 ) post.Link = post.Link.Substring( 0, 200 );
     using ( var conn = DirtBagConnection.GetConn() ) {
         var query = "" +
             "insert into UserPosts (UserName,ThingID,Link,PostTime,ChannelID,ChannelName,Subreddit) " +
             "select @UserName, @ThingID, @Link, @PostTime, @ChannelID, @ChannelName, @Subreddit " +
             "WHERE NOT EXISTS " +
             "(select PostID from UserPosts where Link = @Link) " +
             ";";
         conn.Execute( query, new { post.UserName,post.ThingID, post.Link, post.PostTime, post.ChannelID, post.ChannelName, post.Subreddit } );
     }
 }
コード例 #2
0
ファイル: UserPost.cs プロジェクト: CrustyJew/DirtBag
        public static void UpdatePost( UserPost post )
        {
            if ( post.Link.Length > 200 ) post.Link = post.Link.Substring( 0, 200 );
            using ( var conn = DirtBagConnection.GetConn() ) {
                var query = "" +
                    "update UserPosts " +
                    "set UserName = @UserName, ThingID = @ThingID, Link = @Link, PostTime = @PostTime, ChannelID = @ChannelID, " +
                    "ChannelName = @ChannelName, Subreddit = @Subreddit " +
                    "WHERE PostID = @PostID";

                conn.Execute( query, new { post.UserName, post.ThingID, post.Link, post.PostTime, post.ChannelID, post.ChannelName, post.Subreddit, post.PostID } );
            }
        }
コード例 #3
0
ファイル: UserStalker.cs プロジェクト: CrustyJew/DirtBag
        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 );
        }