Debian Codegraph @

recipes/in4_pl.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 in4(BasicNewsRecipe):
8 title = 'IN4.pl'
9 oldest_article = 7
10 max_articles_per_feed = 100
11 __author__ = 'fenuks'
12 description = 'Serwis Informacyjny - Aktualnosci, recenzje'
13 category = 'IT'
14 language = 'pl'
15 index = 'http://www.in4.pl/'
16 no_stylesheets = True
17 remove_empty_feeds = True
18 preprocess_regexps = [(re.compile(r'<a title="translate into.*?</a>', re.DOTALL), lambda match: '')]
19 keep_only_tags = [dict(name='div', attrs={'class': 'left_alone'})]
20 remove_tags_after = dict(name='img', attrs={'title': 'komentarze'})
21 remove_tags = [dict(name='img', attrs={'title': 'komentarze'})]
22 feeds = [
23 ('Wiadomo\u015bci', 'http://www.in4.pl/rss.php'),
24 ('Recenzje', 'http://www.in4.pl/rss_recenzje.php'),
25 ('Mini recenzje', 'http://www.in4.pl/rss_mini.php'),
26 ]
27
28 def append_page(self, soup, appendtag):
29 a = soup.findAll('a')
30 nexturl = None
31 for i in a:
32 if i.string and 'następna str' in i.string:
33 nexturl = 'http://www.in4.pl/' + i['href']
34 i.extract()
35 while nexturl:
36 soup2 = self.index_to_soup(nexturl)
37 pagetext = soup2.find(id='news')
38 comments = pagetext.findAll(text=lambda text: isinstance(text, Comment))
39 for comment in comments:
40 comment.extract()
41 pos = len(appendtag.contents)
42 appendtag.insert(pos, pagetext)
43 nexturl = None
44 tag = soup2.findAll('a')
45 for z in tag:
46 if z.string and 'następna str' in z.string:
47 nexturl = 'http://www.in4.pl/' + z['href']
48 break
49
50 def preprocess_html(self, soup):
51 self.append_page(soup, soup.body)
52 for a in soup.findAll('a', href=True):
53 if 'http://' not in a['href'] and 'https://' not in a['href']:
54 a['href'] = self.index + a['href']
55 return soup