Debian Codegraph @

recipes/yomiuri_world.recipe

raw
1 __license__ = 'GPL v3'
2 __copyright__ = '2010,2014, Hiroshi Miura <[email protected]>'
3 '''
4 www.yomiuri.co.jp
5 '''
6
7 import re
8
9 from calibre.web.feeds.news import BasicNewsRecipe
10
11
12 class YOLNews(BasicNewsRecipe):
13 title = 'Yomiuri Online (World)'
14 __author__ = 'Hiroshi Miura'
15 oldest_article = 2
16 max_articles_per_feed = 50
17 description = 'Japanese traditional newspaper Yomiuri Online News/world news'
18 publisher = 'Yomiuri Online News'
19 category = 'news, japan'
20 language = 'ja'
21 encoding = 'UTF-8'
22 index = 'http://www.yomiuri.co.jp/world/'
23 remove_javascript = True
24 masthead_title = 'YOMIURI ONLINE'
25
26 keep_only_tags = [{'class': 'article text-resizeable'}]
27
28 def parse_feeds(self):
29 feeds = BasicNewsRecipe.parse_feeds(self)
30 for curfeed in feeds:
31 delList = []
32 for a, curarticle in enumerate(curfeed.articles):
33 if re.search(r'rssad.jp', curarticle.url):
34 delList.append(curarticle)
35 if len(delList) > 0:
36 for d in delList:
37 index = curfeed.articles.index(d)
38 curfeed.articles[index : index + 1] = []
39 return feeds
40
41 def parse_index(self):
42 feeds = []
43 newsarticles = []
44 soup = self.index_to_soup(self.index)
45 mainspan = soup.find('div', attrs={'class': 'pbNested span-main-inr'})
46 if mainspan:
47 topstories = mainspan.find('ul', attrs={'class': 'list-top'})
48 if topstories:
49 for itt in topstories.findAll('li'):
50 itema = itt.find('a', href=True)
51 if itema:
52 item_headline = itema.find('span', attrs={'class': 'headline'})
53 item_date = item_headline.find('span', attrs={'class': 'update'})
54 newsarticles.append({'title': item_headline.contents[0], 'date': item_date, 'url': itema['href'], 'description': ''})
55 secondstories = mainspan.find('ul', attrs={'class': 'list-common'})
56 if secondstories:
57 for itt in secondstories.findAll('li'):
58 itema = itt.find('a', href=True)
59 if itema:
60 item_headline = itema.find('span', attrs={'class': 'headline'})
61 item_date = item_headline.find('span', attrs={'class': 'update'})
62 newsarticles.append({'title': item_headline.contents[0], 'date': item_date, 'url': itema['href'], 'description': ''})
63 feeds.append(('World', newsarticles))
64 return feeds