| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 4 |
|
| 5 |
|
| 6 |
def absurl(url): |
| 7 |
if url.startswith('/'): |
| 8 |
return 'https://sz-magazin.sueddeutsche.de' + url |
| 9 |
|
| 10 |
|
| 11 |
class szmagazin(BasicNewsRecipe): |
| 12 |
title = 'Süddeutsche Zeitung Magazin' |
| 13 |
__author__ = 'unkn0wn' |
| 14 |
description = ( |
| 15 |
'Das SZ-Magazin ist ein Wochenendmagazin, das der Süddeutschen Zeitung (SZ) beiliegt. Es erscheint jeden Freitag und umfasst verschiedene' |
| 16 |
'Themenbereiche wie Politik, Kultur, Gesellschaft, Wissenschaft, Technologie, Reisen, Mode und Lifestyle.' |
| 17 |
) |
| 18 |
masthead_url = 'https://upload.wikimedia.org/wikipedia/commons/8/89/SZ-Magazin_logo.svg' |
| 19 |
encoding = 'utf-8' |
| 20 |
language = 'de' |
| 21 |
remove_attributes = ['style', 'height', 'width'] |
| 22 |
ignore_duplicate_articles = {'url'} |
| 23 |
resolve_internal_links = True |
| 24 |
remove_empty_feeds = True |
| 25 |
no_javascript = True |
| 26 |
no_stylesheets = True |
| 27 |
|
| 28 |
extra_css = ''' |
| 29 |
.figure__caption, .articleheader__author { font-size:small; } |
| 30 |
.articleheader__subline { font-style:italic; color:#202020; } |
| 31 |
blockquote, em { color: #202020; } |
| 32 |
''' |
| 33 |
|
| 34 |
recipe_specific_options = {'issue': {'short': 'The edition to download (YYYY/Number format)', 'long': 'For example, 2024/31'}} |
| 35 |
|
| 36 |
keep_only_tags = [classes('articleheader__headline articleheader__subline articleheader__author articleheader__mediasection articlemain__content')] |
| 37 |
remove_tags = [dict(name=['svg', 'button', 'meta']), classes('articlemain__ad inline-teaser')] |
| 38 |
|
| 39 |
def parse_index(self): |
| 40 |
d = self.recipe_specific_options.get('issue') |
| 41 |
if d and isinstance(d, str): |
| 42 |
issue = 'https://sz-magazin.sueddeutsche.de/heft/' + d |
| 43 |
else: |
| 44 |
url = 'https://sz-magazin.sueddeutsche.de/hefte' |
| 45 |
soup = self.index_to_soup(url) |
| 46 |
issue = absurl(soup.find(**classes('teaser--issue')).a['href']) |
| 47 |
|
| 48 |
soup = self.index_to_soup(issue) |
| 49 |
self.cover_url = soup.find(**classes('issue-page-header__img'))['src'] |
| 50 |
self.title = 'SZ Magazin ' + self.tag_to_string(soup.find(**classes('page-header__headline'))) |
| 51 |
self.description = self.tag_to_string(soup.find(**classes('page-header__text'))) |
| 52 |
self.timefmt = ' [' + self.tag_to_string(soup.find(**classes('issue-page-header-date'))) + ']' |
| 53 |
|
| 54 |
ans = [] |
| 55 |
|
| 56 |
for a in soup.findAll('a', attrs={'class': 'link teaser__text-link'}): |
| 57 |
title = self.tag_to_string(a.h5) |
| 58 |
url = absurl(a['href']) |
| 59 |
desc = self.tag_to_string(a.p) |
| 60 |
self.log(' ', title, '\n\t', desc, '\n\t', url) |
| 61 |
ans.append({'title': title, 'url': url, 'description': desc}) |
| 62 |
return [('Articles', ans)] |
| 63 |
|
| 64 |
def print_version(self, url): |
| 65 |
return 'https://och.to/unlock/' + url.split('?')[0] |
| 66 |
|
| 67 |
def preprocess_html(self, soup): |
| 68 |
h2 = soup.find(**classes('articleheader__subline')) |
| 69 |
if h2: |
| 70 |
h2.name = 'p' |
| 71 |
for bq in soup.findAll('blockquote'): |
| 72 |
h2 = bq.find('h2') |
| 73 |
if h2: |
| 74 |
h2.name = 'h4' |
| 75 |
for img in soup.findAll('img', attrs={'data-src': True}): |
| 76 |
img['src'] = img['data-src'] |
| 77 |
return soup |