コード例 #1
0
ファイル: Reader.cs プロジェクト: wyrover/HackerNewsSummary
        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);
        }
コード例 #2
0
ファイル: Reader.cs プロジェクト: wyrover/HackerNewsSummary
        public async Task <object> CheckForUpdates(dynamic input)
        {
            List <int> top30Ids    = GetTop100(30);
            List <int> currentList = new List <int>();

            object[] idList = (object[])input.idList;
            foreach (object id in idList)
            {
                currentList.Add(Convert.ToInt32((string)id));
            }
            List <int>      newIds     = top30Ids.Except(currentList).ToList();
            List <StoryObj> newStories = new List <StoryObj>();

            foreach (int id in newIds)
            {
                try
                {
                    FullStory fs           = FullStoryFactory.GetFullStory(id);
                    int       commentCount = fs.TotalComments;
                    string    commentUrl   = "https://news.ycombinator.com/item?id=" + id;
                    StoryObj  so           = new StoryObj()
                    {
                        StoryId = id, StoryTitle = fs.title, Author = fs.author, StoryText = fs.text, Url = fs.url ?? commentUrl, CommentUrl = commentUrl, StoryComments = commentCount
                    };
                    newStories.Add(so);
                }
                catch (Exception ex)
                {
                    //Sometimes algolia api throws an error, just move
                    //on to the next item
                    Console.WriteLine(ex.ToString());
                }
            }
            return(newStories);
        }
コード例 #3
0
ファイル: Reader.cs プロジェクト: wyrover/HackerNewsSummary
        public async Task <object> GetStoryTopNWords(int storyid)
        {
            FullStory fs = FullStoryFactory.GetFullStory(storyid);
            Dictionary <string, int> topNWords = fs.GetTopNWordsDictionary(10);
            List <WordObj>           wordObjs  = topNWords.ToList().Select(x => new WordObj()
            {
                Word = x.Key, Count = x.Value
            }).ToList();

            return(wordObjs);
        }
コード例 #4
0
ファイル: Reader.cs プロジェクト: wyrover/HackerNewsSummary
        public async Task <object> GetCommentTreeForId(string idTuple)
        {
            string       sStoryId = idTuple.Split(':')[1];
            string       sNodeId  = idTuple.Split(':')[0];
            int          storyid  = Convert.ToInt32(sStoryId);
            int          nodeid   = Convert.ToInt32(sNodeId);
            FullStory    fs       = FullStoryFactory.GetFullStory(storyid);
            children     child    = fs.GetNodeById(nodeid);
            TagCloudNode tgn      = fs.GetCommentTreeString(child);

            return(JsonConvert.SerializeObject(tgn));
        }
コード例 #5
0
ファイル: Reader.cs プロジェクト: wyrover/HackerNewsSummary
 public async Task <object> ArchiveStory(int id)
 {
     try
     {
         FullStory fs = FullStoryFactory.GetFullStory(id);
         fs.ArchivedOn = DateTime.Now;
         Directory.CreateDirectory("archive");
         string fileName = Path.Combine("archive", id + ".json");
         File.WriteAllText(fileName, JsonConvert.SerializeObject(fs));
     }
     catch (Exception ex)
     {
         return(ex.ToString());
     }
     return(string.Empty);
 }
コード例 #6
0
ファイル: Reader.cs プロジェクト: wyrover/HackerNewsSummary
        public async Task <object> GetTop100Stories(object input)
        {
            List <int>      top100Ids    = GetTop100();
            List <StoryObj> storyObjList = new List <StoryObj>();

            foreach (int id in top100Ids)
            {
                FullStory fs         = FullStoryFactory.GetFullStory(id);
                string    commentUrl = "https://news.ycombinator.com/item?id=" + id;
                StoryObj  so         = new StoryObj()
                {
                    StoryId = id, StoryTitle = fs.title, Author = fs.author, StoryText = fs.text, Url = fs.url ?? commentUrl, CommentUrl = commentUrl
                };
                storyObjList.Add(so);
            }
            return(storyObjList);
        }
コード例 #7
0
ファイル: Reader.cs プロジェクト: wyrover/HackerNewsSummary
        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);
        }
コード例 #8
0
ファイル: Reader.cs プロジェクト: wyrover/HackerNewsSummary
        public async Task <Object> GetStory(int id)
        {
            List <StoryObj> storyObjList = new List <StoryObj>();

            try
            {
                FullStory fs           = FullStoryFactory.GetFullStory(id);
                int       commentCount = fs.TotalComments;
                string    commentUrl   = "https://news.ycombinator.com/item?id=" + id;
                StoryObj  so           = new StoryObj()
                {
                    StoryId = id, StoryTitle = fs.title, Author = fs.author, StoryText = fs.text, Url = fs.url ?? commentUrl, CommentUrl = commentUrl, StoryComments = commentCount
                };
                storyObjList.Add(so);
            }
            catch (Exception ex)
            {
                //Sometimes algolia api throws an error, just move
                //on to the next item
                Console.WriteLine(ex.ToString());
            }
            return(storyObjList);
        }
コード例 #9
0
ファイル: Reader.cs プロジェクト: wyrover/HackerNewsSummary
        public int GetStoryCommentCount(int storyID)
        {
            FullStory fs = FullStoryFactory.GetFullStory(storyID);

            return(fs.TotalComments);
        }