| 1 |
from calibre.web.feeds.recipes import BasicNewsRecipe |
| 2 |
|
| 3 |
__license__ = 'GPL v3' |
| 4 |
__copyright__ = 'Ralf Hein - ralfhein at GMX dot DE' |
| 5 |
''' |
| 6 |
Heise Select Magazine - iX |
| 7 |
''' |
| 8 |
|
| 9 |
|
| 10 |
class heise_select(BasicNewsRecipe): |
| 11 |
issue = None |
| 12 |
# overwrite this for easy download of previous issues |
| 13 |
# issue = '/select/ix/2020/3' |
| 14 |
|
| 15 |
title = 'iX' |
| 16 |
timefmt = '' |
| 17 |
__author__ = 'Ralf Hein' |
| 18 |
needs_subscription = True |
| 19 |
description = 'Das iX Magazin als ePaper. Benötigt Heise Plus Digitalabo (siehe https://www.heise.de/plus/)' |
| 20 |
publisher = 'Heise Verlag' |
| 21 |
authors = 'Heise Verlag' |
| 22 |
category = 'it' |
| 23 |
tags = 'Magazin, IT, computer, ix' |
| 24 |
publication_type = 'magazine' |
| 25 |
no_stylesheets = True |
| 26 |
use_embedded_content = False |
| 27 |
compress_news_images = True |
| 28 |
encoding = 'utf-8' |
| 29 |
language = 'de' |
| 30 |
|
| 31 |
conversion_options = {'base_font_size': 10, 'no_inline_navbars': True, 'language': language, 'publisher': publisher, 'authors': publisher} |
| 32 |
|
| 33 |
# some code cleanup |
| 34 |
remove_tags = [ |
| 35 |
dict(name='meta'), |
| 36 |
dict(name='link', attrs={'rel': 'icon'}), |
| 37 |
dict(name='link', attrs={'rel': 'dns-prefetch'}), |
| 38 |
dict(name='link', attrs={'rel': 'preconnect'}), |
| 39 |
dict(name='div', attrs={'class': 'meta__group--issue'}), |
| 40 |
dict(name='p', attrs={'class': 'comment'}), |
| 41 |
dict(name='div', attrs={'class': 'pswp'}), |
| 42 |
dict(name='div', attrs={'class': 'bottom-links'}), |
| 43 |
] |
| 44 |
|
| 45 |
# content is neatly within <main> element |
| 46 |
remove_tags_before = [dict(name='main')] |
| 47 |
remove_tags_after = [dict(name='main')] |
| 48 |
|
| 49 |
def parse_index(self): |
| 50 |
baseref = 'https://www.heise.de' |
| 51 |
# find current issue if not defined |
| 52 |
if self.issue is None: |
| 53 |
soup = self.index_to_soup(baseref + '/select') |
| 54 |
sec = soup.find('section', attrs={'class': 'magazine--ix'}) |
| 55 |
self.issue = sec.find('a', attrs={'class': 'magazine__link--issue'}, href=True)['href'] |
| 56 |
|
| 57 |
issue_num = self.issue.replace('/select/ix/', '') |
| 58 |
# fix title with issue number to keep them neatly organised |
| 59 |
self.title += ' ' + issue_num.replace('/', '-') |
| 60 |
self.cover_url = 'https://www.heise.de/select/thumbnail/ix/' + issue_num |
| 61 |
|
| 62 |
soup = self.index_to_soup(baseref + self.issue) |
| 63 |
toc = [] |
| 64 |
|
| 65 |
for h3 in soup.findAll('h3', attrs={'class': 'xp__inhalt__title'}): |
| 66 |
section_title = h3.text |
| 67 |
articles = [] |
| 68 |
ul = h3.find_next('ul') |
| 69 |
|
| 70 |
for li in ul.findAll('li', attrs={'class': 'xp__toc__item'}): |
| 71 |
article_uri = li.find('a', attrs={'class': 'xp__link'})['href'] |
| 72 |
article_title = li.find('span', attrs={'class': 'xp__toc__item-subtitle'}).text |
| 73 |
article = {'title': article_title, 'url': baseref + article_uri} |
| 74 |
articles.append(article) |
| 75 |
toc.append((section_title, articles)) |
| 76 |
|
| 77 |
return toc |
| 78 |
|
| 79 |
def get_browser(self): |
| 80 |
br = BasicNewsRecipe.get_browser(self) |
| 81 |
if self.username is not None and self.password is not None: |
| 82 |
loginURL = 'https://www.heise.de/sso/login?forward=%2Fselect' |
| 83 |
br.open(loginURL) |
| 84 |
br.select_form(action='/sso/login/login') |
| 85 |
br['username'] = self.username |
| 86 |
br['password'] = self.password |
| 87 |
br.submit() |
| 88 |
|
| 89 |
return br |
| 90 |
|
| 91 |
def preprocess_html(self, soup): |
| 92 |
# images are dynamically sized via js + a-img tag, epub can not work with this |
| 93 |
# construct ordinary img from it |
| 94 |
for aimg in soup.findAll('a', attrs={'class': 'js-pswp-image'}): |
| 95 |
if aimg['href'] is not None and aimg['data-pswp-bu'] is not None: |
| 96 |
img = soup.new_tag('img', src=aimg['href'], alt=aimg['data-pswp-bu'], style='display: block;') |
| 97 |
if img is not None: |
| 98 |
aimg.replaceWith(img) |
| 99 |
|
| 100 |
return soup |