示例#1
0
 public async Task <object> GetArchivedStories(int id)
 {
     try
     {
         var             directory    = new DirectoryInfo("archive");
         var             files        = directory.GetFiles().OrderByDescending(x => x.LastWriteTime).Where(y => y.Extension == ".json").ToList();
         List <StoryObj> storyObjList = new List <StoryObj>();
         foreach (var file in files)
         {
             string    fileText   = File.ReadAllText(file.FullName);
             FullStory fs         = JsonConvert.DeserializeObject <FullStory>(fileText);
             string    commentUrl = "https://news.ycombinator.com/item?id=" + fs.id;
             StoryObj  so         = new StoryObj()
             {
                 StoryId = fs.id, StoryTitle = fs.title, Author = fs.author, StoryText = fs.text, Url = fs.url ?? commentUrl, CommentUrl = commentUrl, StoryComments = fs.TotalComments, ArchivedOn = fs.ArchivedOn
             };
             storyObjList.Add(so);
         }
         return(storyObjList.OrderByDescending(x => x.ArchivedOn).ToList());
     }
     catch (Exception ex)
     {
         return(ex.ToString());
     }
 }
示例#2
0
 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
        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);
        }
示例#4
0
        public async Task <object> GetFrontPage(int pageNum)
        {
            List <int>      top100Ids    = GetTop100(100).Skip((pageNum - 1) * 30).Take(30).ToList();
            List <StoryObj> storyObjList = new List <StoryObj>();

            Parallel.ForEach(top100Ids, currentId =>
            {
                StoryObj so  = GetFullStoryObj(currentId);
                so.StoryRank = top100Ids.IndexOf(currentId);
                if (so != null)
                {
                    storyObjList.Add(so);
                }
            });
            return(storyObjList.OrderBy(x => x.StoryRank).ToList());
        }
示例#5
0
        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);
        }
示例#6
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);
        }
示例#7
0
 public void OnDataChange(DataSnapshot snapshot)
 {
     foreach (DataSnapshot child in snapshot.Children.ToEnumerable())
     {
         if (child.HasChild("title") && child.HasChild("imgUrl") &&
             child.HasChild("imgCaption") && child.HasChild("overview") &&
             child.HasChild("context") && child.HasChild("importantPoints") &&
             child.HasChild("significance"))
         {
             StoryObj childStory = (StoryObj)child;
             if (childStory.ImgUrl != "false")
             {
                 FirebaseService.stories.Add(childStory);
             }
         }
         else
         {
             //TODO: log this
             Console.WriteLine("Failed Check");
         }
     }
 }
示例#8
0
        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
 public async Task<object> GetArchivedStories(int id)
 {
     try
     {
         var directory = new DirectoryInfo("archive");
         var files = directory.GetFiles().OrderByDescending(x => x.LastWriteTime).Where(y => y.Extension == ".json").ToList();
         List<StoryObj> storyObjList = new List<StoryObj>();
         foreach (var file in files)
         {
             string fileText = File.ReadAllText(file.FullName);
             FullStory fs = JsonConvert.DeserializeObject<FullStory>(fileText);
             string commentUrl = "https://news.ycombinator.com/item?id=" + fs.id;
             StoryObj so = new StoryObj() { StoryId = fs.id, StoryTitle = fs.title, Author = fs.author, StoryText = fs.text, Url = fs.url ?? commentUrl, CommentUrl = commentUrl, StoryComments = fs.TotalComments,ArchivedOn = fs.ArchivedOn};
             storyObjList.Add(so);
         }
         return storyObjList.OrderByDescending(x=>x.ArchivedOn).ToList();
     }
     catch (Exception ex)
     {
         return ex.ToString();
     }
 }
示例#10
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;
 }
示例#11
0
 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;
 }
示例#12
0
 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;
 }