| | | 1 | | using GistBackend.Exceptions; |
| | | 2 | | using GistBackend.Types; |
| | | 3 | | using HtmlAgilityPack; |
| | | 4 | | using static System.Net.WebUtility; |
| | | 5 | | using static GistBackend.Types.FeedType; |
| | | 6 | | using static GistBackend.Types.Language; |
| | | 7 | | |
| | | 8 | | namespace GistBackend.Handlers.RssFeedHandler.Feeds; |
| | | 9 | | |
| | 23 | 10 | | public record BleepingComputer() : RssFeed() |
| | | 11 | | { |
| | 0 | 12 | | public override Uri RssUrl => new("https://www.bleepingcomputer.com/feed/"); |
| | 0 | 13 | | public override Language Language => En; |
| | 0 | 14 | | public override FeedType Type => News; |
| | 0 | 15 | | public override IEnumerable<string> AllowedCategories => ["Security"]; |
| | | 16 | | |
| | | 17 | | public override string ExtractText(string content) |
| | | 18 | | { |
| | 0 | 19 | | var doc = new HtmlDocument(); |
| | 0 | 20 | | doc.LoadHtml(content); |
| | | 21 | | |
| | 0 | 22 | | var entryContent = doc.DocumentNode.SelectSingleNode("//div[@class='articleBody']"); |
| | 0 | 23 | | if (entryContent == null) |
| | | 24 | | { |
| | 0 | 25 | | throw new ExtractingEntryTextException("Missing container element"); |
| | | 26 | | } |
| | | 27 | | |
| | 0 | 28 | | var textContent = entryContent.InnerText; |
| | 0 | 29 | | if (string.IsNullOrWhiteSpace(textContent)) |
| | | 30 | | { |
| | 0 | 31 | | throw new ExtractingEntryTextException("No text found in container"); |
| | | 32 | | } |
| | | 33 | | |
| | 0 | 34 | | var decodedText = HtmlDecode(textContent); |
| | | 35 | | |
| | 0 | 36 | | var trimmed = decodedText.Split("Related Articles:"); |
| | 0 | 37 | | return (trimmed.Length > 0 ? trimmed[0] : decodedText).Trim(); |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | public override bool CheckForSponsoredContent(string content) |
| | | 41 | | { |
| | 0 | 42 | | var doc = new HtmlDocument(); |
| | 0 | 43 | | doc.LoadHtml(content); |
| | 0 | 44 | | var sponsoredNode = doc.DocumentNode.SelectSingleNode("//div[@class='cz-news-title-left-area']/strong"); |
| | 0 | 45 | | return sponsoredNode?.InnerText.Trim() == "Sponsored by"; |
| | | 46 | | } |
| | | 47 | | } |