From 517a3e397575cd34fc77046a79e8d3f29d025ee5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 20 Mar 2011 11:18:18 -0600 Subject: [PATCH] Fix Washington Post --- recipes/wash_post.recipe | 68 ++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 38 deletions(-) diff --git a/recipes/wash_post.recipe b/recipes/wash_post.recipe index fb6d5bc598..3af89d502e 100644 --- a/recipes/wash_post.recipe +++ b/recipes/wash_post.recipe @@ -1,4 +1,3 @@ -import re from calibre.web.feeds.news import BasicNewsRecipe @@ -6,55 +5,48 @@ class WashingtonPost(BasicNewsRecipe): title = 'Washington Post' description = 'US political news' - __author__ = 'Kovid Goyal and Sujata Raman' + __author__ = 'Kovid Goyal' use_embedded_content = False max_articles_per_feed = 20 language = 'en' + encoding = 'utf-8' remove_javascript = True no_stylesheets = True - extra_css = ''' - #articleCopyright { font-family:Arial,helvetica,sans-serif ; font-weight:bold ; font-size:x-small ;} - p { font-family:"Times New Roman",times,serif ; font-weight:normal ; font-size:small ;} - body{font-family:arial,helvetica,sans-serif} - ''' - - feeds = [ ('Today\'s Highlights', 'http://www.washingtonpost.com/wp-dyn/rss/linkset/2005/03/24/LI2005032400102.xml'), - ('Politics', 'http://www.washingtonpost.com/wp-dyn/rss/politics/index.xml'), - ('Nation', 'http://www.washingtonpost.com/wp-dyn/rss/nation/index.xml'), - ('World', 'http://www.washingtonpost.com/wp-dyn/rss/world/index.xml'), - ('Business', 'http://www.washingtonpost.com/wp-dyn/rss/business/index.xml'), - ('Technology', 'http://www.washingtonpost.com/wp-dyn/rss/technology/index.xml'), - ('Health', 'http://www.washingtonpost.com/wp-dyn/rss/health/index.xml'), - ('Education', 'http://www.washingtonpost.com/wp-dyn/rss/education/index.xml'), - ('Style', - 'http://www.washingtonpost.com/wp-dyn/rss/print/style/index.xml'), - ('NFL Sports', - 'http://www.washingtonpost.com/wp-dyn/rss/sports/index/nfl/index.xml'), - ('Redskins', 'http://www.washingtonpost.com/wp-dyn/rss/sports/redskins/index.xml'), - ('Editorials', 'http://www.washingtonpost.com/wp-dyn/rss/linkset/2005/05/30/LI2005053000331.xml'), + feeds = [ + ('Politics', 'http://www.washingtonpost.com/rss/politics'), + ('Nation', 'http://www.washingtonpost.com/rss/national'), + ('World', 'http://www.washingtonpost.com/rss/world'), + ('Business', 'http://www.washingtonpost.com/rss/business'), + ('Lifestyle', 'http://www.washingtonpost.com/rss/lifestyle'), + ('Sports', 'http://www.washingtonpost.com/rss/sports'), + ('Redskins', 'http://www.washingtonpost.com/rss/sports/redskins'), + ('Opinions', 'http://www.washingtonpost.com/rss/opinions'), + ('Entertainment', 'http://www.washingtonpost.com/rss/entertainment'), + ('Local', 'http://www.washingtonpost.com/rss/local'), + ('Investigations', + 'http://www.washingtonpost.com/rss/investigations'), ] - remove_tags = [{'id':['pfmnav', 'ArticleCommentsWrapper']}] + remove_tags = [ + {'class':lambda x: x and 'article-toolbar' in x}, + {'class':lambda x: x and 'quick-comments' in x}, + {'class':lambda x: x and 'tweet' in x}, + {'class':lambda x: x and 'article-related' in x}, + {'class':lambda x: x and 'hidden' in x.split()}, + {'class':lambda x: x and 'also-read' in x.split()}, + {'class':lambda x: x and 'partners-content' in x.split()}, + {'class':['module share', 'module ads', 'comment-vars', 'hidden', + 'share-icons-wrap', 'comments']}, + {'id':['right-rail']}, + ] + keep_only_tags = dict(id=['content', 'article']) - def get_article_url(self, article): - return article.get('guid', article.get('link', None)) def print_version(self, url): - return url.rpartition('.')[0] + '_pf.html' + url = url.rpartition('?')[0] + return url.replace('_story.html', '_singlePage.html') - def postprocess_html(self, soup, first): - for div in soup.findAll(name='div', style=re.compile('margin')): - div['style'] = '' - return soup - - def preprocess_html(self, soup): - for tag in soup.findAll('font'): - if tag.has_key('size'): - if tag['size'] == '+2': - if tag.b: - return soup - return None