Debian Codegraph @

recipes/the_monthly.recipe

raw
1 from calibre.web.feeds.news import BasicNewsRecipe, classes
2
3
4 class monthly(BasicNewsRecipe):
5 title = 'The Monthly'
6 __author__ = 'unkn0wn'
7 description = (
8 'The Monthly is one of Australia’s boldest voices, providing enlightening commentary and vigorous,'
9 ' at times controversial, debate on the issues that affect the nation.'
10 )
11 no_stylesheets = True
12 use_embedded_content = False
13 encoding = 'utf-8'
14 language = 'en_AU'
15 remove_attributes = ['height', 'width']
16 ignore_duplicate_articles = {'url'}
17
18 timefmt = ' [%B %Y]'
19
20 extra_css = '''
21 .article-page__title {font-weight:bold; font-size:large;}
22 .article-page__author, .category, .caption {font-size:small; color:#404040;}
23 .article__summary, .author-details-bottom-wrapper, em {font-style:italic; color:#202020;}
24 '''
25 keep_only_tags = [classes('article-page')]
26 remove_tags = [
27 classes(
28 'node-teaser-hidden article-page__social__icons sidebar-toc article-footer-container'
29 ' article-page__sidebar toc-list-container tm-promo-banner-article-p4-wrapper edition'
30 )
31 ]
32
33 def parse_index(self):
34 soup = self.index_to_soup('https://www.themonthly.com.au/latest-edition')
35 if cov := soup.find(**classes('article__edition-image')):
36 self.cover_url = cov.find('img')['src']
37 self.log(self.cover_url)
38
39 feeds = []
40 main = soup.find(**classes('main'))
41 for art in main.findAll(**classes('article')):
42 if hr := art.find('a', attrs={'href': lambda x: x and x.startswith('/issue/')}):
43 url = 'https://www.themonthly.com.au' + hr['href']
44 elif hr := art.findParent('a', attrs={'href': lambda x: x and x.startswith('/issue/')}):
45 url = 'https://www.themonthly.com.au' + hr['href']
46 title = self.tag_to_string(art.find(**classes('article__title')))
47 desc = ''
48 if text := art.find(**classes('article__text')):
49 desc = self.tag_to_string(text)
50 if auth := art.find(**classes('article__author')):
51 desc = self.tag_to_string(auth) + ' | ' + desc
52 if cat := art.find(**classes('category')):
53 desc = self.tag_to_string(cat) + ' | ' + desc
54 if not title or not url:
55 continue
56 self.log(' ', title, '\n\t', url, '\n\t', desc)
57 feeds.append({'title': title, 'url': url, 'description': desc})
58 return [('The Monthly', feeds)]