Debian Codegraph @

recipes/kopalniawiedzy.recipe

raw
1 __license__ = 'GPL v3'
2 __copyright__ = '2011 Attis <[email protected]>, 2012 Tomasz Długosz <[email protected]>'
3 __version__ = 'v. 0.1'
4
5 import re
6
7 from calibre.web.feeds.recipes import BasicNewsRecipe
8
9
10 class KopalniaWiedzy(BasicNewsRecipe):
11 title = 'Kopalnia Wiedzy'
12 publisher = 'Kopalnia Wiedzy'
13 description = 'Ciekawostki ze świata nauki i techniki'
14 encoding = 'utf-8'
15 __author__ = 'Attis & Tomasz Długosz'
16 language = 'pl'
17 oldest_article = 7
18 max_articles_per_feed = 100
19 INDEX = 'http://kopalniawiedzy.pl/'
20 remove_javascript = True
21 remove_empty_feeds = True
22 no_stylesheets = True
23
24 remove_tags = [
25 {'name': 'p', 'attrs': {'class': 'keywords'}},
26 {'name': 'div', 'attrs': {'class': 'sexy-bookmarks sexy-bookmarks-bg-caring'}},
27 {'name': 'div', 'attrs': {'class': 'article-time-and-cat'}},
28 {'name': 'p', 'attrs': {'class': 'tags'}},
29 ]
30 remove_tags_after = dict(attrs={'class': 'ad-square'})
31 keep_only_tags = [dict(name='div', attrs={'class': 'article-text text-small'})]
32 extra_css = '.topimage {margin-top: 30px}'
33
34 preprocess_regexps = [
35 (re.compile(r'<a .* rel="lightboxText" .*><img (.*)></a>'), lambda match: '<img class="topimage" ' + match.group(1) + '>'),
36 (re.compile(r'<br /><br />'), lambda match: '<br/>'),
37 ]
38
39 feeds = [
40 ('Biologia', 'http://kopalniawiedzy.pl/wiadomosci_biologia.rss'),
41 ('Medycyna', 'http://kopalniawiedzy.pl/wiadomosci_medycyna.rss'),
42 ('Psychologia', 'http://kopalniawiedzy.pl/wiadomosci_psychologia.rss'),
43 ('Technologie', 'http://kopalniawiedzy.pl/wiadomosci_technologie.rss'),
44 ('Ciekawostki', 'http://kopalniawiedzy.pl/wiadomosci_ciekawostki.rss'),
45 ('Artykuły', 'http://kopalniawiedzy.pl/artykuly.rss'),
46 ]
47
48 def is_link_wanted(self, url, tag):
49 return ''.join(tag['class']) == 'next'
50
51 def remove_beyond(self, tag, next):
52 while tag is not None and getattr(tag, 'name', None) != 'body':
53 after = getattr(tag, next)
54 while after is not None:
55 ns = getattr(tag, next)
56 after.extract()
57 after = ns
58 tag = tag.parent
59
60 def append_page(self, soup, appendtag, position):
61 pager = soup.find('a', attrs={'class': 'next'})
62 if pager:
63 nexturl = self.INDEX + pager['href']
64 soup2 = self.index_to_soup(nexturl)
65 texttag = soup2.find('div', attrs={'id': 'articleContent'})
66
67 tag = texttag.find(attrs={'class': 'pages'})
68 self.remove_beyond(tag, 'nextSibling')
69
70 newpos = len(texttag.contents)
71 self.append_page(soup2, texttag, newpos)
72
73 appendtag.insert(position, texttag)
74
75 def preprocess_html(self, soup):
76 self.append_page(soup, soup.body, 3)
77
78 for item in soup.findAll('div', attrs={'class': 'pages'}):
79 item.extract()
80
81 for item in soup.findAll('p', attrs={'class': 'wykop'}):
82 item.extract()
83
84 return soup