private async Task <Usd> GetDataFromHtmlAsync(string htmlPage) { var parser = new HtmlParser(); var document = parser.ParseDocument(htmlPage); var titleValidation = document.GetElementsByTagName("tr").ElementAtOrDefault(1); if (titleValidation == null) { await _slackHooksService.SendNotification(_httpClient); return(null); } var titleText = titleValidation.GetElementsByTagName("td").ElementAtOrDefault(0); if (titleText != null && !titleText.InnerHtml.Equals(_bnaSettings.ValidationHtml)) { await _slackHooksService.SendNotification(_httpClient); return(null); } var usdToday = document.GetElementsByTagName("tr").LastOrDefault(); if (usdToday == null) { await _slackHooksService.SendNotification(_httpClient); return(null); } var buy = usdToday.GetElementsByTagName("td").ElementAtOrDefault(1); var sale = usdToday.GetElementsByTagName("td").ElementAtOrDefault(2); var date = usdToday.GetElementsByTagName("td").ElementAtOrDefault(3); if (buy == null || sale == null) { await _slackHooksService.SendNotification(_httpClient); return(null); } if (date != null) { return new Usd { Date = date.InnerHtml, SaleValue = sale.InnerHtml, BuyValue = buy.InnerHtml } } ; await _slackHooksService.SendNotification(_httpClient); return(null); } }
protected async Task SendSlackNotification( string htmlPage, DateTime dateTime, CurrencyCodeEnum currencyCode, Exception e = null) { Logger.LogError(e ?? new Exception("Error getting HTML"), "Error getting HTML, title is not valid, please check HTML: {Page}", htmlPage); await SlackHooksService.SendNotification($"Can't get currency from {currencyCode} currency code, please check Html in the log or if the date is holiday {dateTime.ToUniversalTime():yyyy-MM-dd}"); }