Updated NYTimes Headlines recipe

This commit is contained in:
Kovid Goyal 2009-07-21 10:00:26 -06:00
parent 69f6df71ae
commit 07d7464a4d

View File

@ -42,11 +42,12 @@ class NYTimes(BasicNewsRecipe):
# By default, no sections are skipped.
excludeSectionKeywords = []
# Add section keywords from the right column above to skip that section
# For example, to skip sections containing the word 'Sports' or 'Dining', use:
# To skip sections containing the word 'Sports' or 'Dining', use:
# excludeSectionKeywords = ['Sports', 'Dining']
# Fetch only Business and Technology
#excludeSectionKeywords = ['Arts','Dining','Editorials','Health','Magazine','Media','Region','Op-Ed','Politics','Science','Sports','Top Stories','Travel','U.S.','World']
# Fetch only Top Stories
#excludeSectionKeywords = ['Arts','Business','Dining','Editorials','Health','Magazine','Media','Region','Op-Ed','Politics','Science','Sports','Technology','Travel','U.S.','World']
@ -70,7 +71,7 @@ class NYTimes(BasicNewsRecipe):
extra_css = '.headline {text-align:left;}\n\
.byline {font:monospace; margin-bottom:0px;}\n\
.source {align:left;}\n\
.credit {align:right;}\n'
.credit {text-align:right;font-size:smaller;}\n'
def get_browser(self):
br = BasicNewsRecipe.get_browser()
@ -268,7 +269,7 @@ class NYTimes(BasicNewsRecipe):
kicker = soup.find(True, {'class':'kicker'})
if kicker is not None :
h3Tag = Tag(soup, "h3")
h3Tag.insert(0, kicker.contents[0])
h3Tag.insert(0, self.tag_to_string(kicker))
kicker.replaceWith(h3Tag)
# Change captions to italic -1
@ -277,7 +278,7 @@ class NYTimes(BasicNewsRecipe):
emTag = Tag(soup, "em")
#emTag['class'] = "caption"
#emTag['font-size-adjust'] = "-1"
emTag.insert(0, caption.contents[0])
emTag.insert(0, self.tag_to_string(caption))
hrTag = Tag(soup, 'hr')
emTag.insert(1, hrTag)
caption.replaceWith(emTag)
@ -285,10 +286,10 @@ class NYTimes(BasicNewsRecipe):
# Change <nyt_headline> to <h2>
headline = soup.find("nyt_headline")
if headline is not None :
tag = Tag(soup, "h2")
tag['class'] = "headline"
tag.insert(0, headline.contents[0])
soup.h1.replaceWith(tag)
h2tag = Tag(soup, "h2")
h2tag['class'] = "headline"
h2tag.insert(0, self.tag_to_string(headline))
headline.replaceWith(h2tag)
# Change <h1> to <h3> - used in editorial blogs
masthead = soup.find("h1")
@ -296,14 +297,14 @@ class NYTimes(BasicNewsRecipe):
# Nuke the href
if masthead.a is not None :
del(masthead.a['href'])
tag = Tag(soup, "h3")
tag.insert(0, masthead.contents[0])
soup.h1.replaceWith(tag)
h3tag = Tag(soup, "h3")
h3tag.insert(0, self.tag_to_string(masthead))
masthead.replaceWith(h3tag)
# Change <span class="bold"> to <b>
for subhead in soup.findAll(True, {'class':'bold'}) :
bTag = Tag(soup, "b")
bTag.insert(0, subhead.contents[0])
bTag.insert(0, self.tag_to_string(subhead))
subhead.replaceWith(bTag)
return soup