from __future__ import unicode_literals import re from calibre.web.feeds.news import BasicNewsRecipe class CNetJapanRelease(BasicNewsRecipe): title = 'CNET Japan release' oldest_article = 3 max_articles_per_feed = 30 __author__ = 'Hiroshi Miura' feeds = [('CNet Release', 'http://feed.japan.cnet.com/rss/release/index.rdf')] language = 'ja' encoding = 'Shift_JIS' remove_javascript = True preprocess_regexps = [ (re.compile((r'.*'), re.DOTALL | re.IGNORECASE | re.UNICODE), lambda match: ''), (re.compile(r'.*', re.DOTALL | re.IGNORECASE), lambda match: ''), (re.compile((r'.*'), re.UNICODE), lambda match: ''), ] remove_tags_before = dict(id='contents_l') remove_tags = [ {'class': 'social_bkm_share'}, {'class': 'social_bkm_print'}, {'class': 'block20 clearfix'}, dict(name='div', attrs={'id': 'bookreview'}), {'class': 'tag_left_ttl'}, ] remove_tags_after = {'class': 'block20'} def parse_feeds(self): feeds = BasicNewsRecipe.parse_feeds(self) for curfeed in feeds: delList = [] for a, curarticle in enumerate(curfeed.articles): if re.search(r'pheedo.jp', curarticle.url): delList.append(curarticle) if len(delList) > 0: for d in delList: index = curfeed.articles.index(d) curfeed.articles[index : index + 1] = [] return feeds