Example #1
0
        public async Task <object> GetFullStory(int storyid)
        {
            FullStory fs           = FullStoryFactory.GetFullStory(storyid);
            string    json         = fs.GetCommentTreeString();
            string    tagCloudJson = fs.GetTagCloudTreeString();
            Dictionary <int, string> commentDictionary = GetCommentDictionary(fs);
            List <CommentObj>        comments          = new List <CommentObj>();
            List <SentenceObj>       topSentenceObjs   = fs.GetTopSentences(5);

            foreach (var item in commentDictionary)
            {
                comments.Add(new CommentObj()
                {
                    Id = item.Key, Text = item.Value
                });
            }
            List <UserCommentObj> userComments = new List <UserCommentObj>();
            var userCommentsForStory           = fs.GetUserComments();

            foreach (var kvp in userCommentsForStory)
            {
                userComments.Add(new UserCommentObj()
                {
                    User = kvp.Key, Comments = kvp.Value
                });
            }
            List <KeywordCommentObj> keywordComments = new List <KeywordCommentObj>();
            var namedObjectsForStory = fs.GetNamedObjects(20);

            foreach (var kvp in namedObjectsForStory)
            {
                keywordComments.Add(new KeywordCommentObj()
                {
                    Keyword = kvp.Key, Comments = kvp.Value
                });
            }
            Directory.CreateDirectory("data");
            string fileName = Path.Combine("data", "following.txt");

            if (!File.Exists(fileName))
            {
                File.Create(fileName);
            }
            string[] following        = File.ReadAllLines(fileName);
            string   csv              = string.Join(",", following);
            string   fileNameWatching = Path.Combine("data", "watching.txt");

            if (!File.Exists(fileNameWatching))
            {
                File.Create(fileNameWatching);
            }
            string[]     watching     = File.ReadAllLines(fileNameWatching);
            string       csvWatching  = string.Join(",", watching);
            FullStoryObj fullStoryObj = new FullStoryObj()
            {
                Json = json, TagCloudJson = tagCloudJson, TotalComments = commentDictionary.Count, Comments = comments, Sentences = topSentenceObjs, UserComments = userComments, KeywordComments = keywordComments, AllFollowing = csv, AllWatching = csvWatching, TotalWords = fs.TotalWords
            };

            return(fullStoryObj);
        }
Example #2
0
        private StoryObj GetFullStoryObj(int id)
        {
            StoryObj so = new StoryObj();

            try
            {
                FullStory fs                 = FullStoryFactory.GetFullStory(id);
                int       commentCount       = fs.TotalComments;
                string    commentUrl         = "https://news.ycombinator.com/item?id=" + id;
                var       usercommentObjList = new List <UserCommentObj>();
                var       dictComments       = fs.GetUserComments();
                foreach (var kvp in dictComments)
                {
                    UserCommentObj userCommentObj = new UserCommentObj()
                    {
                        User = kvp.Key, Comments = kvp.Value, StoryId = id
                    };
                    usercommentObjList.Add(userCommentObj);
                }
                var keywordComments = fs.GetNamedObjects(20);
                List <KeywordCommentObj> keywordCommentObjList = new List <KeywordCommentObj>();
                foreach (var kvp in keywordComments)
                {
                    KeywordCommentObj keywordCommentObj = new KeywordCommentObj()
                    {
                        Keyword = kvp.Key, Comments = kvp.Value, StoryId = id
                    };
                    keywordCommentObjList.Add(keywordCommentObj);
                }
                so = new StoryObj()
                {
                    StoryId = id, StoryTitle = fs.title, Author = fs.author, StoryText = fs.text, Url = fs.url ?? commentUrl, CommentUrl = commentUrl, StoryComments = commentCount, AllUserComments = usercommentObjList, AllKeywordComments = keywordCommentObjList
                };
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            return(so);
        }