| 1 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 2 |
|
| 3 |
|
| 4 |
class DeutscheWelle(BasicNewsRecipe): |
| 5 |
title = 'Deutsche Welle' |
| 6 |
description = 'Nachrichten der Deutschen Welle (DW)' |
| 7 |
publisher = 'DW - [email protected]' |
| 8 |
language = 'de' |
| 9 |
__author__ = 'unkn0wn' |
| 10 |
oldest_article = 2 |
| 11 |
max_articles_per_feed = 200 |
| 12 |
no_stylesheets = True |
| 13 |
remove_javascript = True |
| 14 |
remove_empty_feeds = True |
| 15 |
ignore_duplicate_articles = {'title', 'url'} |
| 16 |
remove_attributes = ['height', 'width', 'style'] |
| 17 |
|
| 18 |
keep_only_tags = [dict(name='article')] |
| 19 |
|
| 20 |
recipe_specific_options = { |
| 21 |
'days': { |
| 22 |
'short': 'Oldest article to download from this news source. In days ', |
| 23 |
'long': 'For example, 0.5, gives you articles from the past 12 hours', |
| 24 |
'default': str(oldest_article), |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
def __init__(self, *args, **kwargs): |
| 29 |
BasicNewsRecipe.__init__(self, *args, **kwargs) |
| 30 |
d = self.recipe_specific_options.get('days') |
| 31 |
if d and isinstance(d, str): |
| 32 |
self.oldest_article = float(d) |
| 33 |
|
| 34 |
remove_tags = [dict(name=['footer', 'source']), dict(attrs={'data-tracking-name': 'sharing-icons-inline'}), classes('kicker advertisement vjs-wrapper')] |
| 35 |
|
| 36 |
# watch out https://www.dw.com/de/service/rss/s-9773 for description of possible rss feeds |
| 37 |
feeds = [ |
| 38 |
('Nachrichten', 'http://rss.dw.com/xml/rss-de-news'), |
| 39 |
('Wissenschaft', 'http://rss.dw.com/xml/rss-de-wissenschaft'), |
| 40 |
('Sport', 'http://rss.dw.com/xml/rss-de-sport'), |
| 41 |
('Deuschland entdecken', 'http://rss.dw.com/xml/rss-de-deutschlandentdecken'), |
| 42 |
('Presse', 'http://rss.dw.com/xml/presse'), |
| 43 |
('Politik', 'http://rss.dw.com/xml/rss_de_politik'), |
| 44 |
('Wirtschaft', 'http://rss.dw.com/xml/rss-de-eco'), |
| 45 |
('Kultur und Leben', 'http://rss.dw.com/xml/rss-de-cul'), |
| 46 |
('Thema des Tages', 'http://rss.dw.com/xml/rss-de-top'), |
| 47 |
] |
| 48 |
|
| 49 |
def preprocess_html(self, soup): |
| 50 |
for img in soup.findAll('img', srcset=True): |
| 51 |
img['src'] = img['srcset'].split()[6] |
| 52 |
return soup |