| 1 |
#!/usr/bin/env python |
| 2 |
## |
| 3 |
## Written: March 2020 |
| 4 |
## Version: 1.2 |
| 5 |
## Last update: 2024-09-26 |
| 6 |
## |
| 7 |
from __future__ import absolute_import, division, print_function, unicode_literals |
| 8 |
|
| 9 |
''' |
| 10 |
Fetch RSS-Feeds from saechsische.de |
| 11 |
''' |
| 12 |
|
| 13 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 14 |
|
| 15 |
|
| 16 |
def prefixed_classes(classes): |
| 17 |
q = frozenset(classes.split(' ')) |
| 18 |
|
| 19 |
def matcher(x): |
| 20 |
if x: |
| 21 |
for candidate in frozenset(x.split()): |
| 22 |
for x in q: |
| 23 |
if candidate.startswith(x): |
| 24 |
return True |
| 25 |
return False |
| 26 |
|
| 27 |
return {'attrs': {'class': matcher}} |
| 28 |
|
| 29 |
|
| 30 |
class RND(BasicNewsRecipe): |
| 31 |
title = 'RedaktionsNetzwerk Deutschland' |
| 32 |
__author__ = 'epubli' |
| 33 |
description = 'RSS-Feeds von RedaktionsNetzwerk Deutschland (rnd.de)' |
| 34 |
publisher = 'RND' |
| 35 |
publication_type = 'newspaper' |
| 36 |
language = 'de' |
| 37 |
encoding = 'UTF-8' |
| 38 |
oldest_article = 1 |
| 39 |
max_articles_per_feed = 40 |
| 40 |
no_stylesheets = True |
| 41 |
remove_javascript = True |
| 42 |
remove_empty_feeds = True |
| 43 |
compress_news_images = True |
| 44 |
compress_news_images_auto_size = 8 |
| 45 |
scale_news_images_to_device = True |
| 46 |
delay = 1 |
| 47 |
ignore_duplicate_articles = {'title', 'url'} |
| 48 |
|
| 49 |
cover_url = 'https://www.designtagebuch.de/wp-content/uploads/mediathek//2022/03/rnd-logo-bildmarke-1500x1125.jpg' |
| 50 |
|
| 51 |
keep_only_tags = [prefixed_classes('ArticleHeadstyled__ArticleHeader- Articlestyled__ArticleBodyWrapper- ArticleImagestyled__ArticleImage-')] |
| 52 |
remove_tags = [ |
| 53 |
prefixed_classes( |
| 54 |
'CallToActionBasestyled__Container- ArticleDetailsstyled__ArticleDetailsToggleCheckbox-' |
| 55 |
' ArticleDetailsstyled__ArticleDetailsToggleButton- ArticleImagestyled__ArticleImageCheckbox-' |
| 56 |
' Adstyled__AdWrapper- MoreItemsBlockstyled__TitleWrapper- MoreItemsBlockstyled__MoreItemsBlock-' |
| 57 |
' ContentTeaserstyled__Article- Buttonstyled__Button-' |
| 58 |
), |
| 59 |
dict(name='source'), |
| 60 |
] |
| 61 |
|
| 62 |
feeds = [ |
| 63 |
('Politik', 'https://www.rnd.de/arc/outboundfeeds/rss/category/politik/'), |
| 64 |
('Wirtschaft', 'https://www.rnd.de/arc/outboundfeeds/rss/category/wirtschaft/'), |
| 65 |
('Sport', 'https://www.rnd.de/arc/outboundfeeds/rss/category/sport/'), |
| 66 |
('Panorama', 'https://www.rnd.de/arc/outboundfeeds/rss/category/panorama/'), |
| 67 |
# ('Promis', 'https://www.rnd.de/arc/outboundfeeds/rss/category/promis/'), |
| 68 |
# ('Reise', 'https://www.rnd.de/arc/outboundfeeds/rss/category/reise/'), |
| 69 |
# ('Medien', 'https://www.rnd.de/arc/outboundfeeds/rss/category/medien/'), |
| 70 |
# ('Digital', 'https://www.rnd.de/arc/outboundfeeds/rss/category/digital/'), |
| 71 |
# ('Kultur', 'https://www.rnd.de/arc/outboundfeeds/rss/category/kultur/'), |
| 72 |
# ('Wissen', 'https://www.rnd.de/arc/outboundfeeds/rss/category/wissen/'), |
| 73 |
# ('Familie', 'https://www.rnd.de/arc/outboundfeeds/rss/category/familie/'), |
| 74 |
# ('Gesundheit', 'https://www.rnd.de/arc/outboundfeeds/rss/category/gesundheit/'), |
| 75 |
# ('Lifestyle', 'https://www.rnd.de/arc/outboundfeeds/rss/category/lifestyle/'), |
| 76 |
# ('Bauen & Wohnen', 'https://www.rnd.de/arc/outboundfeeds/rss/category/bauen-und-wohnen/'), |
| 77 |
# ('Geld & Finanzen', 'https://www.rnd.de/arc/outboundfeeds/rss/category/geld-und-finanzen/'), |
| 78 |
# ('Liebe & Partnerschaft', 'https://www.rnd.de/arc/outboundfeeds/rss/category/liebe-und-partnerschaft/'), |
| 79 |
# ('Beruf & Bildung', 'https://www.rnd.de/arc/outboundfeeds/rss/category/beruf-und-bildung/'), |
| 80 |
# ('E-Mobility', 'https://www.rnd.de/arc/outboundfeeds/rss/category/e-mobility/') |
| 81 |
] |
| 82 |
|
| 83 |
def parse_feeds(self): |
| 84 |
# Call parent's method. |
| 85 |
feeds = BasicNewsRecipe.parse_feeds(self) |
| 86 |
# Loop through all feeds. |
| 87 |
for feed in feeds: |
| 88 |
# Loop through all articles in feed. |
| 89 |
for article in feed.articles[:]: |
| 90 |
# Remove articles with '...' in the url. |
| 91 |
if '/anzeige/' in article.url: |
| 92 |
print('Removing:', article.title) |
| 93 |
feed.articles.remove(article) |
| 94 |
# Remove articles with '...' in the title. |
| 95 |
elif 'Liveticker' in article.title: |
| 96 |
print('Removing:', article.title) |
| 97 |
feed.articles.remove(article) |
| 98 |
elif 'Liveblog' in article.title: |
| 99 |
print('Removing:', article.title) |
| 100 |
feed.articles.remove(article) |
| 101 |
elif 'Newsblog' in article.title: |
| 102 |
print('Removing:', article.title) |
| 103 |
feed.articles.remove(article) |
| 104 |
elif 'Podcast' in article.title: |
| 105 |
print('Removing:', article.title) |
| 106 |
feed.articles.remove(article) |
| 107 |
return feeds |
| 108 |
|
| 109 |
def preprocess_raw_html(self, raw, url): |
| 110 |
# remove articles requiring login and advertisements |
| 111 |
unwantedtag = 'ArticleHeadstyled__ArticleHeadPaidIconContainer' |
| 112 |
if unwantedtag in raw: |
| 113 |
print('Skipping unwanted article with tag:', unwantedtag) |
| 114 |
self.abort_article('Skipping unwanted article') |
| 115 |
|
| 116 |
unwanted_article_keywords = ['Zum Login'] |
| 117 |
for keyword in unwanted_article_keywords: |
| 118 |
if keyword in raw: |
| 119 |
print('Skipping unwanted article with keyword(s):', keyword) |
| 120 |
# self.abort_article('Skipping unwanted article') |
| 121 |
return raw |