| | | 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 T3N() : RssFeed |
| | | 12 | | { |
| | 0 | 13 | | public override Uri RssUrl => new("https://t3n.de/tag/security/rss.xml"); |
| | 0 | 14 | | public override Language Language => De; |
| | 0 | 15 | | public override FeedType Type => News; |
| | 0 | 16 | | public override IEnumerable<string> ForbiddenCategories => ["jobs der woche"]; |
| | | 17 | | |
| | | 18 | | public override bool CheckForPaywall(string content) |
| | | 19 | | { |
| | 0 | 20 | | var doc = new HtmlDocument(); |
| | 0 | 21 | | doc.LoadHtml(content); |
| | | 22 | | |
| | 0 | 23 | | var paywallDiv = doc.DocumentNode.SelectSingleNode($"//div[{ContainsClassSpecifier("c-paywall__wrapper")}]"); |
| | | 24 | | // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract |
| | 0 | 25 | | return paywallDiv is not null; |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | public override string ExtractText(string content) |
| | | 29 | | { |
| | 0 | 30 | | var doc = new HtmlDocument(); |
| | 0 | 31 | | doc.LoadHtml(content); |
| | | 32 | | |
| | 0 | 33 | | var entryContainer = doc.DocumentNode.SelectSingleNode("//div[@class='c-entry']"); |
| | 0 | 34 | | if (entryContainer == null) |
| | | 35 | | { |
| | 0 | 36 | | throw new ExtractingEntryTextException("Missing container element"); |
| | | 37 | | } |
| | | 38 | | |
| | 0 | 39 | | var paragraphsAndHeadings = |
| | 0 | 40 | | entryContainer.SelectNodes($".//p | .//div[{ContainsClassSpecifier("c-article__headline")}]"); |
| | 0 | 41 | | if (paragraphsAndHeadings == null || paragraphsAndHeadings.Count == 0) |
| | | 42 | | { |
| | 0 | 43 | | throw new ExtractingEntryTextException("Missing paragraph or heading elements"); |
| | | 44 | | } |
| | | 45 | | |
| | 0 | 46 | | var combinedTextContents = string.Join("\n", paragraphsAndHeadings.Select(node => node.InnerText)); |
| | 0 | 47 | | if (string.IsNullOrWhiteSpace(combinedTextContents)) |
| | | 48 | | { |
| | 0 | 49 | | throw new ExtractingEntryTextException("No text found in container"); |
| | | 50 | | } |
| | | 51 | | |
| | 0 | 52 | | var decodedText = HtmlDecode(combinedTextContents); |
| | 0 | 53 | | return decodedText.Trim(); |
| | | 54 | | } |
| | | 55 | | } |