| | | 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 | | using static GistBackend.Utils.RssFeedUtils; |
| | | 8 | | |
| | | 9 | | namespace GistBackend.Handlers.RssFeedHandler.Feeds; |
| | | 10 | | |
| | 23 | 11 | | public record ArsTechnicaTechnologyLab() : RssFeed() |
| | | 12 | | { |
| | 0 | 13 | | public override Uri RssUrl => new("https://feeds.arstechnica.com/arstechnica/technology-lab"); |
| | 0 | 14 | | public override Language Language => En; |
| | 0 | 15 | | public override FeedType Type => News; |
| | 0 | 16 | | public override IEnumerable<string> AllowedCategories => ["Security"]; |
| | | 17 | | |
| | | 18 | | public override string ExtractText(string content) |
| | | 19 | | { |
| | 0 | 20 | | var doc = new HtmlDocument(); |
| | 0 | 21 | | doc.LoadHtml(content); |
| | | 22 | | |
| | 0 | 23 | | var entryContents = doc.DocumentNode.SelectNodes($"//div[{ContainsClassSpecifier("post-content")}]"); |
| | 0 | 24 | | if (entryContents == null || entryContents.Count == 0) |
| | | 25 | | { |
| | 0 | 26 | | throw new ExtractingEntryTextException("Missing container element"); |
| | | 27 | | } |
| | | 28 | | |
| | 0 | 29 | | var combinedText = string.Join("", entryContents.Select(node => node.InnerText)); |
| | 0 | 30 | | if (string.IsNullOrWhiteSpace(combinedText)) |
| | | 31 | | { |
| | 0 | 32 | | throw new ExtractingEntryTextException("No text found in container"); |
| | | 33 | | } |
| | | 34 | | |
| | 0 | 35 | | var decodedText = HtmlDecode(combinedText); |
| | 0 | 36 | | return decodedText.Trim().Replace("\n", " "); |
| | | 37 | | } |
| | | 38 | | } |
| | | 39 | | |