Debian Codegraph @

recipes/gazeta-prawna-calibre-v1.recipe

raw
1 #!/usr/bin/env python
2
3 __license__ = 'GPL v3'
4 __copyright__ = '2020, Tomasz Jozwiak <[email protected]>'
5 __author__ = 'Tomasz Jozwiak'
6 '''
7 gazetaprawna.pl
8 '''
9
10 import re
11
12 from calibre.web.feeds.news import BasicNewsRecipe
13
14
15 class gazetaprawna(BasicNewsRecipe):
16 version = 2
17 title = 'Gazeta Prawna'
18 __author__ = 'Tomasz Jozwiak'
19 publisher = 'Infor Biznes'
20 max_articles_per_feed = 30
21 no_stylesheets = True
22 remove_javascript = True
23 remove_empty_feeds = True
24 category = 'newspaper'
25 publication_type = 'newspaper'
26 description = 'Polski dziennik gospodarczy'
27 language = 'pl'
28 encoding = 'utf-8'
29 ignore_duplicate_articles = {'title', 'url'}
30 use_embedded_content = False
31 oldest_article = 1
32
33 extra_css = '''
34 .psavBigImgTitle {font-size:50%;}
35 .psavImgContent {font-size:50%;}
36 .leadDiv {font-weight: bold;}
37 .date {font-size:50%;}
38 .articleGate {font-style: italic; font-weight: normal; font-size:50%;}
39 '''
40
41 remove_tags_before = [dict(name='div', attrs={'class': ['article']}), dict(name='div', attrs={'itemprop': ['breadcrumb']})]
42
43 remove_tags_after = [
44 dict(name='div', attrs={'class': ['articleBody', 'artPayWall', 'contentGalBottom', 'komentarze-forum']}),
45 ]
46
47 remove_tags = [
48 dict(name='span', attrs={'class': ['psav_bigphoto', 'psav_speclinkarea', 'psav_video_target']}),
49 dict(name='div', attrs={'class': ['shareArticleButtons nowe2', 'artPayWall', 'contentGalBottom', 'contentGalTop', 'video-target', 'komentarze-forum']}),
50 dict(name=['link', 'meta', 'style']),
51 dict(name='div', attrs={'itemprop': ['breadcrumb']}),
52 dict(name='section', attrs={'class': ['videoSection']}),
53 ]
54
55 feeds = [
56 ('Z ostatniej chwili', 'http://rss.gazetaprawna.pl/GazetaPrawna'),
57 ('Biznes i prawo gospodarcze', 'http://rss.gazetaprawna.pl/GazetaPrawna-Biznes'),
58 ('Prawo i wymiar sprawiedliwo\u015bci', 'http://rss.gazetaprawna.pl/GazetaPrawna-Prawo'),
59 ('Praca i ubezpieczenia', 'http://rss.gazetaprawna.pl/GazetaPrawna-Praca'),
60 ('Podatki i rachunkowo\u015b\u0107', 'http://rss.gazetaprawna.pl/GazetaPrawna-Podatki'),
61 ('Finanse - waluty i notowania', 'http://rss.gazetaprawna.pl/GazetaPrawna-Finanse'),
62 ]
63
64 def parse_feeds(self):
65 self.log(_('Gazeta Prawna overrode parse_feeds()'))
66 parsed_feeds = BasicNewsRecipe.parse_feeds(self)
67 for n, feed in enumerate(parsed_feeds):
68 for a, article in enumerate(feed):
69 article.text_summary = re.sub(r'<\!\[CDATA\[', '', article.text_summary)
70 article.text_summary = re.sub(r'\]\]', '', article.text_summary)
71 article.summary = article.text_summary
72
73 return parsed_feeds
74
75 def preprocess_html(self, soup):
76 for Img in soup.findAll(name='div', attrs={'class': ['psavBigImg']}):
77 for img_tag in Img.findAll(name='img', attrs={'data-src': True}):
78 img_tag['src'] = img_tag['data-src']
79 del img_tag['data-src']
80 # print(Img.prettify())
81
82 for span in soup.findAll(name='span'):
83 if len(self.tag_to_string(span)) > 1:
84 span.append(' ')
85
86 for locked in soup.findAll(name='div', attrs={'class': ['articleGate']}):
87 locked.append('Przejd\u017a do artyku\u0142u na GazetaPrawna.pl aby zalogowa\u0107 si\u0119 lub wykupi\u0107 dost\u0119p')
88
89 return soup
90
91 def populate_article_metadata(self, article, soup, first):
92 Img = soup.find(name='div', attrs={'class': ['psavBigImg']})
93 if Img:
94 img_tag = Img.find(name='img', attrs={'src': True})
95 if img_tag:
96 self.add_toc_thumbnail(article, img_tag['src'])
97 self.log(_('adding thumbnail: %s to Article') % (img_tag['src']))
98 article.author = 'Gazeta prawna.pl'
99 if len(article.title) > 80:
100 title = article.title[:80]
101 title = title.rsplit(None, 1)
102 article.title = title[0]
103 self.log(_('The title cuting in %s to keep the thumbnail visible') % (article.url))
104
105 def get_cover_url(self):
106 soup = self.index_to_soup('http://www.egazety.pl/infor/e-wydanie-dziennik-gazeta-prawna.html')
107 self.cover_url = soup.find('a', {'class': 'image cover-preview'}).img['src']
108 return getattr(self, 'cover_url', self.cover_url)