Exemplo n.º 1
0
        private static async Task <bool> TryUpdateArticleData(ArticlePost articlePost, Reddit r, CloudTable articleTable, ILogger log)
        {
            bool    result  = false;
            Comment comment = r.GetComment(new Uri("https://www.reddit.com" + articlePost.CommentUri));
            Post    post    = (Post)comment.Parent;

            string articleUrl = post.Url.GetComponents(UriComponents.Host | UriComponents.Path | UriComponents.Scheme, UriFormat.SafeUnescaped);

            using (HttpResponseMessage articleResponse = await client.GetAsync(articleUrl))
            {
                SeattleTimesArticle seattleTimesArticle = new SeattleTimesArticle(articleResponse);
                if (seattleTimesArticle.Headline != articlePost.ArticleHeadline)
                {
                    log.LogInformation("new headline: " + seattleTimesArticle.Headline);
                    articlePost.ArticleHeadline = seattleTimesArticle.Headline;
                    result = true;
                }
                if (seattleTimesArticle.ByLineAuthors.FirstOrDefault() != articlePost.ArticleAuthor)
                {
                    string author = seattleTimesArticle.ByLineAuthors.FirstOrDefault();
                    log.LogInformation("new author: " + author);
                    articlePost.ArticleAuthor = author;
                    result = true;
                }
                if (result)
                {
                    await articleTable.ExecuteAsync(TableOperation.InsertOrReplace(articlePost));
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        internal static async Task <string> GetCommentLine(ArticlePost articlePost, ILogger log, NewsBankClient newsBankClient)
        {
            log.LogInformation("GetCommentLine");

            SearchResult searchResult = null;

            try
            {
                searchResult = await newsBankClient.Search(
                    new SearchRequest()
                {
                    Product      = Product.WorldNews,
                    Publications = new List <Publication>()
                    {
                        Publication.SeattleTimesWebEditionArticles
                    },
                    SearchParameter0 = new SearchParameter()
                    {
                        Field = SearchField.Author, Value = articlePost.ArticleAuthor.Replace("/", string.Empty)
                    },
                    SearchParameter1 = new SearchParameter()
                    {
                        Field = SearchField.Headline, Value = $"\"{articlePost.ArticleHeadline}\"", ParameterCompoundOperator = CompoundOperator.AND
                    },
                    SearchParameter2 = new SearchParameter()
                    {
                        Field = SearchField.Date, Value = articlePost.ArticleDate.ToShortDateString(), ParameterCompoundOperator = CompoundOperator.AND
                    }
                });
            }
            catch (NullReferenceException nullRefEx)  //not the best option.
            {
                log.LogError("possible no Web edition result, " + articlePost.CommentUri);
                log.LogError(nullRefEx.Message);
                log.LogError(nullRefEx.StackTrace);
                return(string.Empty);
            }
            catch (Exception e)
            {
                log.LogError(e.Message);
                throw;
            }
            return($"[NewsBank version]({searchResult.FirstSearchResultItem.ResultItemUri}) via SPL [^(SPL) ^(account) ^(required)](https://www.spl.org/using-the-library/get-started/get-started-with-a-library-card/library-card-application)");
        }