Debian Codegraph @

recipes/cnetjapan_release.recipe

raw
1 from __future__ import unicode_literals
2
3 import re
4
5 from calibre.web.feeds.news import BasicNewsRecipe
6
7
8 class CNetJapanRelease(BasicNewsRecipe):
9 title = 'CNET Japan release'
10 oldest_article = 3
11 max_articles_per_feed = 30
12 __author__ = 'Hiroshi Miura'
13
14 feeds = [('CNet Release', 'http://feed.japan.cnet.com/rss/release/index.rdf')]
15 language = 'ja'
16 encoding = 'Shift_JIS'
17 remove_javascript = True
18
19 preprocess_regexps = [
20 (re.compile((r'<!--\u25B2contents_left END\u25B2-->.*</body>'), re.DOTALL | re.IGNORECASE | re.UNICODE), lambda match: '</body>'),
21 (re.compile(r'<!--AD_ELU_HEADER-->.*</body>', re.DOTALL | re.IGNORECASE), lambda match: '</body>'),
22 (re.compile((r'<!-- \u25B2\u95A2\u9023\u30BF\u30B0\u25B2 -->.*<!-- \u25B2ZDNet\u25B2 -->'), re.UNICODE), lambda match: '<!-- removed -->'),
23 ]
24
25 remove_tags_before = dict(id='contents_l')
26 remove_tags = [
27 {'class': 'social_bkm_share'},
28 {'class': 'social_bkm_print'},
29 {'class': 'block20 clearfix'},
30 dict(name='div', attrs={'id': 'bookreview'}),
31 {'class': 'tag_left_ttl'},
32 ]
33 remove_tags_after = {'class': 'block20'}
34
35 def parse_feeds(self):
36
37 feeds = BasicNewsRecipe.parse_feeds(self)
38
39 for curfeed in feeds:
40 delList = []
41 for a, curarticle in enumerate(curfeed.articles):
42 if re.search(r'pheedo.jp', curarticle.url):
43 delList.append(curarticle)
44 if len(delList) > 0:
45 for d in delList:
46 index = curfeed.articles.index(d)
47 curfeed.articles[index : index + 1] = []
48
49 return feeds