Exemplo n.º 1
0
        /// <summary>
        /// Create funny post from reddit post
        /// </summary>
        /// <param name="rp"></param>
        /// <returns>Post or null in case of error</returns>
        internal static async Task <Post> createFunnyPost(RedditPost rp)
        {
            // funny post
            Post fp = new Post {
                Title = rp.Title, RedditId = rp.Id
            };

            // timestamp
            fp.Created = UNIX_START.AddSeconds(rp.Created_Utc);

            // get direct link to picture
            fp.ImageUrl = await createPictureLink(rp.Url);

            if (fp.ImageUrl == null)
            {
                // no picture => no post
                return(null);
            }

            // fetch comments
            try
            {
                List <RedditComment> comments = await RedditScraper.ParseComments(fp.RedditId);

                // take 3 first comments to be added into db
                foreach (RedditComment comment in comments.Take(3))
                {
                    fp.Comments.Add(new Comment {
                        Text = comment.Body
                    });
                }
            }
            catch (WebException we)
            {
                // comments are not crucial, so we just forget them in case of error
                Debug.WriteLine(we.Message);
            }
            return(fp);
        }
Exemplo n.º 2
0
 public void ParseComments()
 {
     List <RedditComment> lrc = RedditScraper.ParseComments("31ho69").Result;
     //List<RedditComment> lrc = RedditScraper.ParseComments("31ixrv").Result;
     //List<RedditComment> lrc = RedditScraper.ParseComments("31iw5k").Result;
 }