Пример #1
0
        public static string GetOutputDataString(HabrArticle habrArticle)
        {
            if (habrArticle != null)
            {
                var tagsString = "";

                foreach (var tag in habrArticle.Tags)
                {
                    tagsString += "\n" + tag;
                }

                return("\n\nТема: " + habrArticle.Theme + "\n\nНазвание статьи:\n" + habrArticle.Title + "\n\nТеги:\n" + tagsString + "\n\nДата публикации статьи: " + habrArticle.PublicationDate);
            }
            else
            {
                return("Статья не найдена =(");
            }
        }
Пример #2
0
        public static HabrArticle GetHabrArticleFromInternet(int articleId)
        {
            HtmlDocument document;

            try
            {
                var web = new HtmlWeb();
                document = web.Load(Resources.postString + articleId + "/");
            }
            catch (System.Net.WebException ex)
            {
                return(null);
            }

            try
            {
                var tags     = document.DocumentNode.SelectNodes("//a[contains(@class,'hub')]");
                var tempTags = new List <string>();
                tempTags.AddRange(tags.Select(x => x.InnerText));


                var habrArticle = new HabrArticle
                {
                    HabrId          = articleId,
                    Theme           = document.DocumentNode.SelectSingleNode("//h1[contains(@class,'post__title')]//a").InnerText,
                    Title           = document.DocumentNode.SelectNodes("//h1[contains(@class,'post__title')]//span")[1].InnerText,
                    Tags            = tempTags,
                    PublicationDate = document.DocumentNode.SelectSingleNode("//span[contains(@class,'post__time_published')]").InnerText
                };

                return(habrArticle);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Пример #3
0
        public static void AddHabrArticleToDb(HabrArticle habrArticle)
        {
            Connect();

            _habrArticleCollection?.InsertOne(habrArticle);
        }