Debian Codegraph @

recipes/dziennik_wschodni.recipe

raw
1 import re
2
3 from calibre.ebooks.BeautifulSoup import Comment
4 from calibre.web.feeds.news import BasicNewsRecipe
5
6
7 class DziennikWschodni(BasicNewsRecipe):
8 title = 'Dziennik Wschodni'
9 __author__ = 'fenuks'
10 description = 'Dziennik Wschodni - portal regionalny województwa lubelskiego.'
11 category = 'newspaper'
12 language = 'pl'
13 encoding = 'iso-8859-2'
14 extra_css = 'ul {list-style: none; padding:0; margin:0;}'
15 INDEX = 'http://www.dziennikwschodni.pl'
16 masthead_url = INDEX + '/images/top_logo.png'
17 oldest_article = 7
18 max_articles_per_feed = 100
19 remove_empty_feeds = True
20 no_stylesheets = True
21 ignore_duplicate_articles = {'title', 'url'}
22
23 preprocess_regexps = [
24 (re.compile(r'Czytaj:.*?</a>', re.DOTALL), lambda match: ''),
25 (re.compile('Przeczytaj także:.*?</a>', re.DOTALL | re.IGNORECASE), lambda match: ''), # noqa: E501, RUF039
26 (re.compile(r'Przeczytaj również:.*?</a>', re.DOTALL | re.IGNORECASE), lambda match: ''),
27 (re.compile(r'Zobacz też:.*?</a>', re.DOTALL | re.IGNORECASE), lambda match: ''),
28 ] # noqa: E501, RUF039
29
30 keep_only_tags = [dict(id=['article', 'cover', 'photostory'])]
31 remove_tags = [
32 dict(
33 id=[
34 'articleTags',
35 'articleMeta',
36 'boxReadIt',
37 'articleGalleries',
38 'articleConnections',
39 'ForumArticleComments',
40 'articleRecommend',
41 'jedynkiLinks',
42 'articleGalleryConnections',
43 'photostoryConnections',
44 'articleEpaper',
45 'articlePoll',
46 'articleAlarm',
47 'articleByline',
48 ]
49 ),
50 dict(attrs={'class': 'articleFunctions'}),
51 ]
52
53 feeds = [
54 ('Wszystkie', 'http://www.dziennikwschodni.pl/rss.xml'),
55 ('Lublin', 'http://www.dziennikwschodni.pl/lublin.xml'),
56 ('Zamość', 'http://www.dziennikwschodni.pl/zamosc.xml'),
57 ('Biała Podlaska', 'http://www.dziennikwschodni.pl/biala_podlaska.xml'),
58 ('Chełm', 'http://www.dziennikwschodni.pl/chelm.xml'),
59 ('Kraśnik', 'http://www.dziennikwschodni.pl/krasnik.xml'),
60 ('Puławy', 'http://www.dziennikwschodni.pl/pulawy.xml'),
61 ('Świdnik', 'http://www.dziennikwschodni.pl/swidnik.xml'),
62 ('Łęczna', 'http://www.dziennikwschodni.pl/leczna.xml'),
63 ('Lubartów', 'http://www.dziennikwschodni.pl/lubartow.xml'),
64 ('Sport', 'http://www.dziennikwschodni.pl/sport.xml'),
65 ('Praca', 'http://www.dziennikwschodni.pl/praca.xml'),
66 ('Dom', 'http://www.dziennikwschodni.pl/dom.xml'),
67 ('Moto', 'http://www.dziennikwschodni.pl/moto.xml'),
68 ('Zdrowie', 'http://www.dziennikwschodni.pl/zdrowie.xml'),
69 ]
70
71 def get_cover_url(self):
72 soup = self.index_to_soup(self.INDEX + '/apps/pbcs.dll/section?Category=JEDYNKI')
73 nexturl = self.INDEX + soup.find(id='covers').find('a')['href']
74 soup = self.index_to_soup(nexturl)
75 self.cover_url = self.INDEX + soup.find(id='cover').find(name='img')['src']
76 return getattr(self, 'cover_url', self.cover_url)
77
78 def append_page(self, soup, appendtag):
79 tag = soup.find('span', attrs={'class': 'photoNavigationPages'})
80 if tag:
81 number = int(tag.string.rpartition('/')[-1].replace('&nbsp;', ''))
82 baseurl = self.INDEX + soup.find(attrs={'class': 'photoNavigationNext'})['href'][:-1]
83
84 for r in appendtag.findAll(attrs={'class': 'photoNavigation'}):
85 r.extract()
86 for nr in range(2, number + 1):
87 soup2 = self.index_to_soup(baseurl + str(nr))
88 pagetext = soup2.find(id='photoContainer')
89 if pagetext:
90 pos = len(appendtag.contents)
91 appendtag.insert(pos, pagetext)
92 pagetext = soup2.find(attrs={'class': 'photoMeta'})
93 if pagetext:
94 pos = len(appendtag.contents)
95 appendtag.insert(pos, pagetext)
96 pagetext = soup2.find(attrs={'class': 'photoStoryText'})
97 if pagetext:
98 pos = len(appendtag.contents)
99 appendtag.insert(pos, pagetext)
100
101 comments = appendtag.findAll(text=lambda text: isinstance(text, Comment))
102 for comment in comments:
103 comment.extract()
104
105 def preprocess_html(self, soup):
106 self.append_page(soup, soup.body)
107 return soup