Improved recipe for The Christian Science Monitor

This commit is contained in:
Kovid Goyal 2009-10-08 09:59:30 -06:00
parent 4fd2585773
commit 26d992843d

View File

@ -1,5 +1,6 @@
import re import re
from calibre import strftime
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
class ChristianScienceMonitor(BasicNewsRecipe): class ChristianScienceMonitor(BasicNewsRecipe):
@ -7,9 +8,9 @@ class ChristianScienceMonitor(BasicNewsRecipe):
title = 'Christian Science Monitor' title = 'Christian Science Monitor'
description = 'Providing context and clarity on national and international news, peoples and cultures' description = 'Providing context and clarity on national and international news, peoples and cultures'
max_articles_per_feed = 20 max_articles_per_feed = 20
__author__ = 'Kovid Goyal' __author__ = 'Kovid Goyal and Sujata Raman'
language = 'en' language = 'en'
encoding = 'utf-8'
no_stylesheets = True no_stylesheets = True
use_embedded_content = False use_embedded_content = False
@ -23,26 +24,60 @@ class ChristianScienceMonitor(BasicNewsRecipe):
lambda match : '</body>'), lambda match : '</body>'),
]] ]]
extra_css = '''
h1{ color:#000000;font-family: Georgia,Times,"Times New Roman",serif; font-size: large}
.sub{ color:#000000;font-family: Georgia,Times,"Times New Roman",serif; font-size: small;}
.byline{ font-family:Arial,Helvetica,sans-serif ; color:#999999; font-size: x-small;}
.postdate{color:#999999 ; font-family:Arial,Helvetica,sans-serif ; font-size: x-small; }
h3{color:#999999 ; font-family:Arial,Helvetica,sans-serif ; font-size: x-small; }
.photoCutline{ color:#333333 ; font-family:Arial,Helvetica,sans-serif ; font-size: x-small; }
.photoCredit{ color:#999999 ; font-family:Arial,Helvetica,sans-serif ; font-size: x-small; }
#story{font-family:Arial,Tahoma,Verdana,Helvetica,sans-serif ; font-size: small; }
#main{font-family:Arial,Tahoma,Verdana,Helvetica,sans-serif ; font-size: small; }
#photo-details{ font-family:Arial,Helvetica,sans-serif ; color:#999999; font-size: x-small;}
span.name{color:#205B87;font-family: Georgia,Times,"Times New Roman",serif; font-size: x-small}
p#dateline{color:#444444 ; font-family:Arial,Helvetica,sans-serif ; font-style:italic;}
'''
feeds = [
(u'Top Stories' , u'http://rss.csmonitor.com/feeds/top'),
(u'World' , u'http://rss.csmonitor.com/feeds/world'),
(u'USA' , u'http://rss.csmonitor.com/feeds/usa'),
(u'Commentary' , u'http://rss.csmonitor.com/feeds/commentary'),
(u'Money' , u'http://rss.csmonitor.com/feeds/wam'),
(u'Learning' , u'http://rss.csmonitor.com/feeds/learning'),
(u'Living', u'http://rss.csmonitor.com/feeds/living'),
(u'Innovation', u'http://rss.csmonitor.com/feeds/scitech'),
(u'Gardening', u'http://rss.csmonitor.com/feeds/gardening'),
(u'Environment',u'http://rss.csmonitor.com/feeds/environment'),
(u'Arts', u'http://rss.csmonitor.com/feeds/arts'),
(u'Books', u'http://rss.csmonitor.com/feeds/books'),
(u'Home Forum' , u'http://rss.csmonitor.com/feeds/homeforum')
]
def parse_index(self): keep_only_tags = [
soup = self.index_to_soup('http://www.csmonitor.com/textedition') dict(name='div', attrs={'id':['story','main']}),
feeds = [] ]
for tag in soup.findAll(['h2', 'p']):
if tag.name == 'h2': remove_tags = [
title = self.tag_to_string(tag) dict(name='div', attrs={'id':['story-tools','videoPlayer','storyRelatedBottom','enlarge-photo','photo-paginate']}),
feeds.append((title, [])) dict(name='div', attrs={'class':[ 'spacer3','divvy spacer7','comment','storyIncludeBottom']}),
elif tag.has_key('class') and tag['class'] == 'story' and feeds: dict(name='ul', attrs={'class':[ 'centerliststories']}) ,
a = tag.find('a') dict(name='form', attrs={'id':[ 'commentform']}) ,
if a is not None and a.has_key('href'): ]
art = {
'title': self.tag_to_string(a),
'url' : 'http://www.csmonitor.com'+a['href'], def find_articles(self, section):
'date' : '', ans = []
} for x in section.findAll('head4'):
a.extract() title = ' '.join(x.findAll(text=True)).strip()
art['description'] = self.tag_to_string(tag).strip() a = x.find('a')
feeds[-1][1].append(art) if not a: continue
return feeds href = a['href']
ans.append({'title':title, 'url':href, 'description':'', 'date': strftime('%a, %d %b')})
#for x in ans:
# x['url'] += '/output/print'
return ans
def postprocess_html(self, soup, first_fetch): def postprocess_html(self, soup, first_fetch):
html = soup.find('html') html = soup.find('html')