Fix #824490 (New recipe for The Independent)

This commit is contained in:
Kovid Goyal 2011-08-11 10:24:04 -06:00
parent 52256a641b
commit 0a96cf092d
2 changed files with 77 additions and 61 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 B

View File

@ -1,70 +1,86 @@
__license__ = 'GPL v3'
__copyright__ = '2011, Darko Miletic <darko.miletic at gmail.com>'
'''
www.independent.co.uk
'''
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import BeautifulSoup from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag
class TheIndependent(BasicNewsRecipe): class TheIndependent(BasicNewsRecipe):
title = u'The Independent' title = 'The Independent'
language = 'en_GB' __author__ = 'Darko Miletic'
__author__ = 'Krittika Goyal' description = 'Independent News - Breaking news, comment and features from The Independent newspaper'
oldest_article = 1 #days publisher = 'The Independent'
max_articles_per_feed = 30 category = 'news, politics, UK'
encoding = 'latin1' oldest_article = 2
max_articles_per_feed = 200
no_stylesheets = True
encoding = 'cp1252'
use_embedded_content = False
language = 'en_GB'
remove_empty_feeds = True
publication_type = 'newspaper'
masthead_url = 'http://www.independent.co.uk/independent.co.uk/images/logo-london.png'
extra_css = """
h1{font-family: Georgia,serif }
body{font-family: Verdana,Arial,Helvetica,sans-serif}
img{margin-bottom: 0.4em; display:block}
.info,.caption,.credits{font-size: x-small}
"""
no_stylesheets = True conversion_options = {
#remove_tags_before = dict(name='h1', attrs={'class':'heading'}) 'comment' : description
#remove_tags_after = dict(name='td', attrs={'class':'newptool1'}) , 'tags' : category
remove_tags = [ , 'publisher' : publisher
dict(name='iframe'), , 'language' : language
dict(name='div', attrs={'class':'related-articles'}), }
dict(name='div', attrs={'id':['qrformdiv', 'inSection', 'alpha-inner']}),
dict(name='ul', attrs={'class':'article-tools'}),
dict(name='ul', attrs={'class':'articleTools'}),
]
feeds = [ remove_tags =[
('UK', dict(name=['meta','link','object','embed','iframe','base','style'])
'http://www.independent.co.uk/news/uk/rss'), ,dict(attrs={'class':['related-articles','share','googleCols','article-tools','paging','googleArt']})
('World', ,dict(attrs={'id':['newsVideoPlayer','yahoobook','google-intext']})
'http://www.independent.co.uk/news/world/rss'), ]
('Business', keep_only_tags =[dict(attrs={'id':'article'})]
'http://www.independent.co.uk/news/business/rss'), remove_attributes=['lang','onclick','width','xmlns:fb']
('People',
'http://www.independent.co.uk/news/people/rss'),
('Science',
'http://www.independent.co.uk/news/science/rss'),
('Media',
'http://www.independent.co.uk/news/media/rss'),
('Education',
'http://www.independent.co.uk/news/education/rss'),
('Obituaries',
'http://www.independent.co.uk/news/obituaries/rss'),
('Opinion',
'http://www.independent.co.uk/opinion/rss'),
('Environment', feeds = [
'http://www.independent.co.uk/environment/rss'), (u'UK' , u'http://www.independent.co.uk/news/uk/rss' )
,(u'World' , u'http://www.independent.co.uk/news/world/rss' )
('Sport', ,(u'Business' , u'http://www.independent.co.uk/news/business/rss' )
'http://www.independent.co.uk/sport/rss'), ,(u'People' , u'http://www.independent.co.uk/news/people/rss' )
,(u'Science' , u'http://www.independent.co.uk/news/science/rss' )
('Life and Style', ,(u'Media' , u'http://www.independent.co.uk/news/media/rss' )
'http://www.independent.co.uk/life-style/rss'), ,(u'Education' , u'http://www.independent.co.uk/news/education/rss' )
,(u'Leading Articles' , u'http://www.independent.co.uk/opinion/leading-articles/rss')
('Arts and Entertainment', ,(u'Comentators' , u'http://www.independent.co.uk/opinion/commentators/rss' )
'http://www.independent.co.uk/arts-entertainment/rss'), ,(u'Columnists' , u'http://www.independent.co.uk/opinion/columnists/rss' )
,(u'Letters' , u'http://www.independent.co.uk/opinion/letters/rss' )
('Travel', ,(u'Big Question' , u'http://www.independent.co.uk/extras/big-question/rss' )
'http://www.independent.co.uk/travel/rss'), ,(u'Sport' , u'http://www.independent.co.uk/sport/rss' )
,(u'Life&Style' , u'http://www.independent.co.uk/life-style/rss' )
('Money', ,(u'Arts&Entertainment' , u'http://www.independent.co.uk/arts-entertainment/rss' )
'http://www.independent.co.uk/money/rss'), ,(u'Travel' , u'http://www.independent.co.uk/travel/rss' )
] ,(u'Money' , u'http://www.independent.co.uk/money/rss' )
]
def get_article_url(self, article):
return article.get('guid', None)
def preprocess_html(self, soup): def preprocess_html(self, soup):
story = soup.find(name='div', attrs={'id':'mainColumn'}) for item in soup.body.findAll(style=True):
#td = heading.findParent(name='td') del item['style']
#td.extract() for item in soup.body.findAll(['author','preform']):
soup = BeautifulSoup('<html><head><title>t</title></head><body></body></html>') item.name='span'
body = soup.find(name='body') for item in soup.body.findAll('img'):
body.insert(0, story) if not item.has_key('alt'):
return soup item['alt'] = 'image'
for item in soup.body.findAll('div', attrs={'class':['clear-o','body','photoCaption']}):
item.name = 'p'
for item in soup.body.findAll('div'):
if not item.attrs and not item.contents:
item.extract()
soup2 = BeautifulSoup('<html><head><title>t</title></head><body></body></html>')
soup2.body.replaceWith(soup.body)
return soup2