public void ParseComment(string themeURL, Comment comment, ref User user)
        {
            user.TotalComments += 1;

            //check if they posted a link
            if (comment.BodyHTML.Contains("<a") && comment.BodyHTML.Contains(">"))
            {
                user.TotalLinks += 1;

                if (comment.Body.Contains(@"/nostreak") == false)
                {
                    if (user.DaysPostedLinks.Contains(themeURL) == false)
                        user.DaysPostedLinks.Add(themeURL);
                }
                else
                {
                    if (user.ExcludedFromStreakLinks.Contains(themeURL) == false)
                        user.ExcludedFromStreakLinks.Add(themeURL);
                    Console.WriteLine("Skipping comment for " + user.Username + ": " + comment.Link);
                }
            }

            // check for webpage link
            if (comment.BodyHTML.ToLower().Contains("my webpage"))
            {
                string pattern = "<a href=\\\"(.*?)\\\">my webpage</a>";
                Match match = Regex.Match(comment.BodyHTML.ToLower(), pattern);
                if(match.Success && string.IsNullOrEmpty(user.Webpage))
                    user.Webpage = match.Groups[1].Value;
            }
            user.Upvotes += comment.Ups;
            user.Downvotes += comment.Downs;

            if(user.MostRecentPost < comment.CreatedDate)
                user.MostRecentPost = comment.CreatedDate;
        }
コード例 #2
0
        private static bool ExportUserStatisticsToFile(User user, string file)
        {
            Console.Write("Exporting user stats to file " + file + "... ");
            MD5 md5 = MD5.Create();
            string originalHash = "";

            if (File.Exists(file))
            {
                Console.Write("Found existing stats file. Opening for comparison... ");
                FileStream originalFileStream = File.OpenRead(file);
                originalHash = BitConverter.ToString(md5.ComputeHash(originalFileStream)).Replace("-", "").ToLower();
                originalFileStream.Close();
            }

            StreamWriter writer = File.CreateText(file);

            writer.WriteLine("{");
            writer.WriteLine("  \"Username\": \"" + user.Username + "\",");
            writer.WriteLine("  \"CurrentStreak\": \"" + user.CurrentStreak + "\",");
            writer.WriteLine("  \"Downvotes\": \"" + user.Downvotes + "\",");
            writer.WriteLine("  \"LongestStreak\": \"" + user.LongestStreak + "\",");
            writer.WriteLine("  \"TotalComments\": \"" + user.TotalComments + "\",");
            writer.WriteLine("  \"TotalLinks\": \"" + user.TotalLinks + "\",");
            writer.WriteLine("  \"TotalThemesForStreak\": \"" + user.DaysPostedLinks.Count + "\",");
            writer.WriteLine("  \"TotalNoStreakComments\": \"" + user.ExcludedFromStreakLinks.Count + "\",");
            writer.WriteLine("  \"Upvotes\": \"" + user.Upvotes + "\",");
            writer.WriteLine("  \"Karma\": \"" + user.Karma + "\",");
            writer.WriteLine("  \"MostRecentUserActivity\": \"" + user.MostRecentPost.ToString() + "\",");

            writer.WriteLine("  \"NostreakThemes\" : [ ");
            foreach (string url in user.ExcludedFromStreakLinks)
                writer.WriteLine("      {\"url\": \"" + url + "\"},");
            writer.WriteLine("  ],");

            writer.WriteLine("  \"ThemesPostedTo\" : [ ");
            foreach (string url in user.DaysPostedLinks)
                writer.WriteLine("      {\"url\": \"" + url + "\"},");
            writer.WriteLine("  ],");

            writer.WriteLine("}");

            writer.Close();

            Console.WriteLine("Done writing to file.");

            FileStream newFileStream = File.OpenRead(file);
            string newHash = BitConverter.ToString(md5.ComputeHash(newFileStream)).Replace("-", "").ToLower();
            newFileStream.Close();

            return originalHash != newHash;
        }