Debian Codegraph @

recipes/heise_ct.recipe

raw
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 - ct
7 '''
8
9
10 class heise_select(BasicNewsRecipe):
11 issue = None
12 # overwrite this for easy download of previous issues
13 # issue = '/select/ct/2020/8'
14
15 title = 'Heise ct'
16 timefmt = ''
17 __author__ = 'Ralf Hein'
18 needs_subscription = True
19 description = 'Das ct 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, ct'
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 remove_tags = [
34 dict(name='meta'),
35 dict(name='link', attrs={'rel': 'icon'}),
36 dict(name='link', attrs={'rel': 'dns-prefetch'}),
37 dict(name='link', attrs={'rel': 'preconnect'}),
38 dict(name='div', attrs={'class': 'meta__group--issue'}),
39 dict(name='p', attrs={'class': 'comment'}),
40 dict(name='div', attrs={'class': 'pswp'}),
41 dict(name='div', attrs={'class': 'bottom-links'}),
42 ]
43
44 remove_tags_before = [dict(name='main')]
45 remove_tags_after = [dict(name='main')]
46
47 def parse_index(self):
48 baseref = 'https://www.heise.de'
49 # find current issue if not defined
50 if self.issue is None:
51 soup = self.index_to_soup(baseref + '/select')
52 sec = soup.find('section', attrs={'class': 'magazine--ct'})
53 self.issue = sec.find('a', attrs={'class': 'magazine__link--issue'}, href=True)['href']
54
55 issue_num = self.issue.replace('/select/ct/', '')
56 # fix title with issue number to keep them neatly organised
57 self.title += ' ' + issue_num.replace('/', '-')
58 self.cover_url = 'https://www.heise.de/select/thumbnail/ct/' + issue_num
59
60 soup = self.index_to_soup(baseref + self.issue)
61 toc = []
62
63 for h3 in soup.findAll('h3', attrs={'class': 'xp__inhalt__title'}):
64 section_title = h3.text
65 articles = []
66 ul = h3.find_next('ul')
67
68 for li in ul.findAll('li', attrs={'class': 'xp__toc__item'}):
69 article_uri = li.find('a', attrs={'class': 'xp__link'})['href']
70 article_title = li.find('span', attrs={'class': 'xp__toc__item-subtitle'}).text
71 article = {'title': article_title, 'url': baseref + article_uri}
72 articles.append(article)
73 toc.append((section_title, articles))
74
75 return toc
76
77 def get_browser(self):
78 br = BasicNewsRecipe.get_browser(self)
79 if self.username is not None and self.password is not None:
80 loginURL = 'https://www.heise.de/sso/login?forward=%2Fselect'
81 br.open(loginURL)
82 br.select_form(action='/sso/login/login')
83 br['username'] = self.username
84 br['password'] = self.password
85 br.submit()
86
87 return br
88
89 def preprocess_html(self, soup):
90 # images are dynamically sized via js + a-img tag, epub can not work with this
91 # construct ordinary img from it
92 for aimg in soup.findAll('a', attrs={'class': 'js-pswp-image'}):
93 if aimg['href'] is not None and aimg['data-pswp-bu'] is not None:
94 img = soup.new_tag('img', src=aimg['href'], alt=aimg['data-pswp-bu'], style='display: block;')
95 if img is not None:
96 aimg.replaceWith(img)
97
98 return soup