Debian Codegraph @

recipes/chicago_tribune.recipe

raw
1 #!/usr/bin/env python
2 from __future__ import with_statement
3
4 __license__ = 'GPL 3'
5 __copyright__ = '2009, Kovid Goyal <[email protected]>'
6 __docformat__ = 'restructuredtext en'
7
8 from datetime import date, timedelta
9
10 from calibre.web.feeds.news import BasicNewsRecipe
11
12
13 def classes(classes):
14 q = frozenset(classes.split(' '))
15 return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)})
16
17
18 class ChicagoTribune(BasicNewsRecipe):
19 title = 'Chicago Tribune'
20 __author__ = 'unkn0wn'
21 description = 'Politics, local and business news from Chicago'
22 language = 'en_US'
23 masthead_url = 'https://www.chicagotribune.com/wp-content/uploads/2023/12/2560px-Chicago_Tribune_Logo.svg-1.png'
24 use_embedded_content = False
25 no_stylesheets = True
26 remove_javascript = True
27 remove_attributes = ['width', 'height', 'style']
28 ignore_duplicate_articles = {'title', 'url'}
29 resolve_internal_links = True
30 extra_css = '''
31 img {display:block; margin:0 auto;}
32 em, blockquote { color:#202020; }
33 .coauthor-avatar-container, .calibre-nuked-tag-figcaption {font-size:small;}
34 '''
35
36 def get_cover_url(self):
37 soup = self.index_to_soup('https://en.kiosko.net/us/np/chicago_tribune.html')
38 return 'https:' + soup.find('img', attrs={'id': 'portada'})['src']
39
40 keep_only_tags = [
41 classes('headlines header-features coauthor-avatar-container article-body'),
42 ]
43 remove_tags = [
44 dict(name=['aside', 'svg']),
45 classes('wp-remixd-voice-wrapper wp-embedded-content div-gpt-ad-cube_article entry-section'),
46 ]
47
48 def parse_index(self):
49 index = 'https://www.chicagotribune.com/'
50 soup = self.index_to_soup(index)
51 feeds = []
52 tdy = date.today().strftime('/%Y/%m/%d/')
53 yest = (date.today() - timedelta(days=1)).strftime('/%Y/%m/%d/')
54 for a in soup.findAll('a', attrs={'href': lambda x: x and (tdy in x or yest in x)}):
55 if a.find('img'):
56 continue
57 url = a['href'].split('?')[0]
58 title = self.tag_to_string(a)
59 if not title:
60 continue
61 self.log(title, url)
62 feeds.append({'title': title, 'url': url})
63 return [('Articles', feeds)]
64
65 def preprocess_html(self, soup):
66 for img in soup.findAll('img', attrs={'data-src': True}):
67 img['src'] = img['data-src']
68 return soup