Manual de usuario de calibre, Publicación 2.73.0
# nightmare.
elif 'scorecards' in article.url:
feed.articles.remove(article)
return feeds
# End of class and file.
Esta fórmula muestra sólo la punta del iceberg en lo que se refiere a la potencia de calibre. Para explorar más sobre las
capacidades de calibre, examinaremos un ejemplo de la vida real más complejo en la siguiente sección.
Ejemplo de la vida real
Un ejemplo real bastante complejo que expone más partes de la API de BasicNewsRecipe es la fórmula de The
New York Times
import string, re
from calibre import strftime
from calibre.web.feeds.recipes import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import BeautifulSoup
class NYTimes(BasicNewsRecipe):
title
= 'The New York Times'
__author__ = 'Kovid Goyal'
description = 'Daily news from the New York Times'
timefmt = ' [%a, %d %b, %Y]'
needs_subscription = True
remove_tags_before = dict(id='article')
remove_tags_after = dict(id='article')
remove_tags = [dict(attrs={'class':['articleTools', 'post-tools', 'side_tool',
˓→'nextArticleLink clearfix']}),
dict(id=['footer', 'toolsRight', 'articleInline', 'navigation',
˓→'archive', 'side_search', 'blog_sidebar', 'side_tool', 'side_index']),
dict(name=['script', 'noscript', 'style'])]
encoding = 'cp1252'
no_stylesheets = True
extra_css = 'h1 {font: sans-serif large;}\n.byline {font:monospace;}'
def get_browser(self):
br = BasicNewsRecipe.get_browser()
if self.username is not None and self.password is not None:
br.open('http://www.nytimes.com/auth/login')
br.select_form(name='login')
br['USERID']
= self.username
br['PASSWORD'] = self.password
br.submit()
return br
def parse_index(self):
soup = self.index_to_soup('http://www.nytimes.com/pages/todayspaper/index.html
˓→')
def feed_title(div):
return ''.join(div.findAll(text=True, recursive=False)).strip()
articles = {}
1.2. Añadir su sitio de noticias favorito
43