Debian Codegraph @

recipes/polter_pl.recipe

raw
1 __license__ = 'GPL v3'
2 import re
3
4 from calibre.web.feeds.news import BasicNewsRecipe
5
6
7 class Polter(BasicNewsRecipe):
8 title = 'Polter.pl'
9 __author__ = 'fenuks'
10 description = 'Największy polski serwis poświęcony ogólno pojętej fantastyce - grom fabularnym (RPG), książkom, filmowi, komiksowi, grom planszowym, karcianym i bitewnym.' # noqa: E501
11 category = 'fantasy, books, rpg, games'
12 language = 'pl'
13 extra_css = '.image, .floatright {float: right; margin-left: 10px;} .floatleft {float: left; margin-right: 10px;} .calibre_navbar {clear: both;} .p_title {font-weight: bold;} .p_image {margin-left: auto; margin-right: auto; display: block;} .italic {font-style: italic;}' # noqa: E501
14 cover_url = 'http://static.polter.pl/sub/promo/bpromo2524.jpg'
15 use_embedded_content = False
16 oldest_article = 7
17 max_articles_per_feed = 100
18 no_stylesheets = True
19 remove_empty_feeds = True
20 remove_javascript = True
21 remove_attributes = ['font', 'fieldset', 'onclick']
22 ignore_duplicate_articles = {'title', 'url'}
23
24 keep_only_tags = [dict(attrs={'class': 'boxcontent'})]
25 remove_tags = [dict(id='komentarze'), dict(name='div', attrs={'class': 'ostatnieArtykuly'})]
26 remove_tags_after = dict(id='komentarze')
27
28 feeds = [
29 ('Wieści', 'http://polter.pl/wiesci,rss.html'),
30 ('RPG', 'http://rpg.polter.pl/wiesci,rss.html'),
31 ('Książki', 'http://ksiazki.polter.pl/wiesci,rss.html'),
32 ('Film', 'http://film.polter.pl/wiesci,rss.html'),
33 ('Komiks', 'http://komiks.polter.pl/wiesci,rss.html'),
34 ('Gry bitewne', 'http://bitewniaki.polter.pl/wiesci,rss.html'),
35 ('Gry karciane', 'http://karcianki.polter.pl/wiesci,rss.html'),
36 ('Gry planszowe', 'http://planszowki.polter.pl/wiesci,rss.html'),
37 ('Gry PC', 'http://gry.polter.pl/wiesci,rss.html'),
38 ('Gry konsolowe', 'http://konsole.polter.pl/wiesci,rss.html'),
39 ('Konwenty', 'http://konwenty.polter.pl/wiesci,rss.html'),
40 ]
41
42 def preprocess_html(self, soup):
43 for s in soup.findAll(attrs={'style': re.compile(r'float: ?left')}):
44 s['class'] = 'floatleft'
45 for s in soup.findAll(attrs={'style': re.compile(r'float: ?right')}):
46 s['class'] = 'floatright'
47 for s in soup.findAll(style=True):
48 if 'bold;' in s['style']:
49 if s.get('class', ''):
50 s['class'] = ''.join(s['class']) + ' p_title'
51 else:
52 s['class'] = 'p_title'
53 if 'italic;' in s['style']:
54 if s.get('class', ''):
55 s['class'] = ''.join(s['class']) + ' italic'
56 else:
57 s['class'] = 'italic'
58 del s['style']
59
60 tag = soup.find(id='twoja_ocena')
61 if tag:
62 tag.parent.extract()
63 for tag in soup.findAll(id='lista_chce_ile'):
64 tag.parent.parent.extract()
65 for r in soup.findAll(name='a', href=re.compile(r'^http://www.ceneo.pl/')):
66 r.extract()
67 return soup
68
69 def preprocess_raw_html(self, raw_html, url):
70 return raw_html.replace('<br /><br /><h3>Czytaj również</h3>', '')