| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
## |
| 4 |
## Written: October 2012 (new coding) |
| 5 |
## Version: 10.0 |
| 6 |
## Last update: 2025-01-15 |
| 7 |
## |
| 8 |
|
| 9 |
from __future__ import absolute_import, division, print_function, unicode_literals |
| 10 |
|
| 11 |
__license__ = 'GPL v3' |
| 12 |
__copyright__ = '' |
| 13 |
''' |
| 14 |
Fetch RSS-Feeds spektrum.de |
| 15 |
''' |
| 16 |
|
| 17 |
|
| 18 |
def classes(classes): |
| 19 |
q = frozenset(classes.split(' ')) |
| 20 |
return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)}) |
| 21 |
|
| 22 |
|
| 23 |
from calibre.web.feeds.recipes import BasicNewsRecipe |
| 24 |
|
| 25 |
|
| 26 |
class Spektrum(BasicNewsRecipe): |
| 27 |
title = 'Spektrum der Wissenschaft' |
| 28 |
__author__ = 'Armin Geller, Bratzzo, Rainer Zenz, update epubli' |
| 29 |
description = 'German online portal of Spektrum der Wissenschaft' |
| 30 |
publisher = 'Spektrum der Wissenschaft Verlagsgesellschaft mbH' |
| 31 |
category = 'science news, Germany' |
| 32 |
oldest_article = 3 |
| 33 |
max_articles_per_feed = 100 |
| 34 |
no_stylesheets = True |
| 35 |
remove_javascript = True |
| 36 |
remove_empty_feeds = True |
| 37 |
language = 'de' |
| 38 |
encoding = 'utf8' |
| 39 |
ignore_duplicate_articles = {'title'} |
| 40 |
scale_news_images_to_device = True |
| 41 |
compress_news_images = True |
| 42 |
|
| 43 |
cover_url = 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1d/Spektrum_der_Wissenschaft_Logo_seit_2016.svg/640px-Spektrum_der_Wissenschaft_Logo_seit_2016.svg.png' |
| 44 |
masthead_url = 'http://www.spektrum.de/fm/861/spektrum.de.png' |
| 45 |
|
| 46 |
feeds = [ |
| 47 |
('Spektrum.de', 'http://www.spektrum.de/alias/rss/spektrum-de-rss-feed/996406'), |
| 48 |
] |
| 49 |
|
| 50 |
keep_only_tags = [dict(name='article', attrs={'class': 'content'}), classes('callout-box')] |
| 51 |
|
| 52 |
remove_tags = [ |
| 53 |
classes('hide-for-print'), |
| 54 |
classes('content__meta'), |
| 55 |
classes('content__author'), |
| 56 |
classes('content__video'), |
| 57 |
dict(name='div', attrs={'role': 'navigation'}), |
| 58 |
dict(name='span', attrs={'class': 'sr-only'}), |
| 59 |
] |
| 60 |
|
| 61 |
def parse_feeds(self): |
| 62 |
unwanted_article_types = [ |
| 63 |
'podcast', |
| 64 |
'video', |
| 65 |
'raetsel', |
| 66 |
'leseprobe', |
| 67 |
# 'kolumne', |
| 68 |
# 'rezension', |
| 69 |
# 'news', |
| 70 |
] |
| 71 |
# Call parent's method. |
| 72 |
feeds = BasicNewsRecipe.parse_feeds(self) |
| 73 |
# Loop through all feeds. |
| 74 |
for feed in feeds: |
| 75 |
# Loop through all articles in feed. |
| 76 |
for article in feed.articles[:]: |
| 77 |
if 'VIDEO' in article.title: |
| 78 |
feed.articles.remove(article) |
| 79 |
continue |
| 80 |
# Remove articles with '..' in the url. |
| 81 |
for keyword in unwanted_article_types: |
| 82 |
if keyword in article.url: |
| 83 |
feed.articles.remove(article) |
| 84 |
continue |
| 85 |
|
| 86 |
return feeds |
| 87 |
|
| 88 |
def preprocess_html(self, soup): |
| 89 |
for noscript in soup.findAll('noscript'): |
| 90 |
noscript.name = 'div' |
| 91 |
return soup |
| 92 |
|
| 93 |
def preprocess_raw_html(self, raw, url): |
| 94 |
# remove articles requiring login and advertisements |
| 95 |
unwantedtag = 'content pw-premium' |
| 96 |
if unwantedtag in raw: |
| 97 |
self.abort_article('Skipping unwanted article with tag:' + unwantedtag) |
| 98 |
return raw |