mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Fix #5026 (The Atlantic Feed Seems to Be Broken in 0.6.43)
This commit is contained in:
parent
5196de8f4b
commit
cbfb4ac520
@ -5,76 +5,103 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
'''
|
'''
|
||||||
theatlantic.com
|
theatlantic.com
|
||||||
'''
|
'''
|
||||||
import re
|
import string
|
||||||
|
|
||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
|
from calibre.ebooks.BeautifulSoup import Tag, NavigableString
|
||||||
|
|
||||||
class TheAtlantic(BasicNewsRecipe):
|
class TheAtlantic(BasicNewsRecipe):
|
||||||
|
|
||||||
title = 'The Atlantic'
|
title = 'The Atlantic'
|
||||||
__author__ = 'Kovid Goyal and Sujata Raman'
|
__author__ = 'Kovid Goyal and Sujata Raman'
|
||||||
description = 'Current affairs and politics focussed on the US'
|
description = 'Current affairs and politics focussed on the US'
|
||||||
INDEX = 'http://www.theatlantic.com/doc/current'
|
INDEX = 'http://www.theatlantic.com/magazine/toc/0/'
|
||||||
language = 'en'
|
language = 'en'
|
||||||
|
|
||||||
remove_tags_before = dict(name='div', id='storytop')
|
remove_tags_before = dict(name='div', id='articleHead')
|
||||||
remove_tags = [
|
remove_tags_after = dict(id='copyright')
|
||||||
dict(name='div', id=['seealso','storybottom', 'footer', 'ad_banner_top', 'sidebar','articletoolstop','subcontent',]),
|
remove_tags = [dict(id=['header', 'printAds', 'pageControls'])]
|
||||||
dict(name='p', attrs={'id':["pagination"]}),
|
no_stylesheets = True
|
||||||
dict(name='table',attrs={'class':"tools"}),
|
|
||||||
dict(name='style'),
|
|
||||||
dict(name='a', href='/a/newsletters.mhtml')
|
def print_version(self, url):
|
||||||
]
|
return url.replace('/archive/', '/print/')
|
||||||
remove_attributes = ['icap', 'callout', 'style']
|
|
||||||
no_stylesheets = True
|
|
||||||
conversion_options = { 'linearize_tables':True }
|
|
||||||
|
|
||||||
extra_css = '''
|
|
||||||
#timestamp{font-family:Arial,Helvetica,sans-serif; color:#666666 ;font-size:x-small}
|
|
||||||
#storytype{font-family:Arial,Helvetica,sans-serif; color:#D52B1E ;font-weight:bold; font-size:x-small}
|
|
||||||
h2{font-family:georgia,serif; font-style:italic;font-size:x-small;font-weight:normal;}
|
|
||||||
h1{font-family:georgia,serif; font-weight:bold; font-size:large}
|
|
||||||
#byline{font-family:georgia,serif; font-weight:bold; font-size:x-small}
|
|
||||||
#topgraf{font-family:Arial,Helvetica,sans-serif;font-size:x-small;font-weight:bold;}
|
|
||||||
.artsans{{font-family:Arial,Helvetica,sans-serif;font-size:x-small;}
|
|
||||||
'''
|
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
articles = []
|
articles = []
|
||||||
|
|
||||||
soup = self.index_to_soup(self.INDEX)
|
soup = self.index_to_soup(self.INDEX)
|
||||||
|
sectit = soup.find('h1', attrs={'class':'sectionTitle'})
|
||||||
|
if sectit is not None:
|
||||||
|
texts = sectit.findAll('cufontext')
|
||||||
|
texts = map(self.tag_to_string, texts[-2:])
|
||||||
|
self.timefmt = ' [%s]'%(''.join(texts))
|
||||||
|
|
||||||
issue = soup.find('span', attrs={'class':'issue'})
|
cover = soup.find('img', src=True, attrs={'class':'cover'})
|
||||||
if issue:
|
|
||||||
self.timefmt = ' [%s]'%self.tag_to_string(issue).rpartition('|')[-1].strip().replace('/', '-')
|
|
||||||
|
|
||||||
cover = soup.find('img', alt=re.compile('Cover'), src=True)
|
|
||||||
if cover is not None:
|
if cover is not None:
|
||||||
self.cover_url = 'http://theatlantic.com'+cover['src']
|
self.cover_url = cover['src']
|
||||||
|
|
||||||
for item in soup.findAll('div', attrs={'class':'item'}):
|
feeds = []
|
||||||
a = item.find('a')
|
for section in soup.findAll('div', attrs={'class':'magazineSection'}):
|
||||||
if a and a.has_key('href'):
|
section_title = section.find(attrs={'class':'sectionHeader'})
|
||||||
|
section_title = string.capwords(self.tag_to_string(section_title))
|
||||||
|
self.log('Found section:', section_title)
|
||||||
|
articles = []
|
||||||
|
for post in section.findAll('div', attrs={'class':'post'}):
|
||||||
|
h = post.find(['h3', 'h4'])
|
||||||
|
title = self.tag_to_string(h)
|
||||||
|
a = post.find('a', href=True)
|
||||||
url = a['href']
|
url = a['href']
|
||||||
if not url.startswith('http://'):
|
if url.startswith('/'):
|
||||||
url = 'http://www.theatlantic.com/'+url
|
url = 'http://www.theatlantic.com'+url
|
||||||
url = url.replace('/doc/', '/doc/print/')
|
p = post.find('p', attrs={'class':'dek'})
|
||||||
title = self.tag_to_string(a)
|
desc = None
|
||||||
if title in ('VIDEO', 'AUDIO', 'INTERACTIVE MAP', 'SIDEBAR', 'RECIPES'):
|
self.log('\tFound article:', title, 'at', url)
|
||||||
continue
|
if p is not None:
|
||||||
title = title.replace('&', '&')
|
desc = self.tag_to_string(p)
|
||||||
byline = item.find(attrs={'class':'byline'})
|
self.log('\t\t', desc)
|
||||||
date = self.tag_to_string(byline) if byline else ''
|
articles.append({'title':title, 'url':url, 'description':desc,
|
||||||
description = ''
|
'date':''})
|
||||||
|
feeds.append((section_title, articles))
|
||||||
|
|
||||||
self.log('\tFound article:', title)
|
poems = []
|
||||||
self.log('\t\t', url)
|
self.log('Found section: Poems')
|
||||||
|
for poem in soup.findAll('div', attrs={'class':'poem'}):
|
||||||
|
title = self.tag_to_string(poem.find('h4'))
|
||||||
|
desc = self.tag_to_string(poem.find(attrs={'class':'author'}))
|
||||||
|
url = 'http://www.theatlantic.com'+poem.find('a')['href']
|
||||||
|
self.log('\tFound article:', title, 'at', url)
|
||||||
|
self.log('\t\t', desc)
|
||||||
|
poems.append({'title':title, 'url':url, 'description':desc,
|
||||||
|
'date':''})
|
||||||
|
if poems:
|
||||||
|
feeds.append(('Poems', poems))
|
||||||
|
|
||||||
articles.append({
|
self.log('Found section: Advice')
|
||||||
'title':title,
|
div = soup.find(id='advice')
|
||||||
'date':date,
|
title = self.tag_to_string(div.find('h4'))
|
||||||
'url':url,
|
url = 'http://www.theatlantic.com'+div.find('a')['href']
|
||||||
'description':description
|
desc = self.tag_to_string(div.find('p'))
|
||||||
})
|
self.log('\tFound article:', title, 'at', url)
|
||||||
|
self.log('\t\t', desc)
|
||||||
|
|
||||||
|
feeds.append(('Advice', [{'title':title, 'url':url, 'description':desc,
|
||||||
|
'date':''}]))
|
||||||
|
return feeds
|
||||||
|
|
||||||
|
def postprocess_html(self, soup, first):
|
||||||
|
for table in soup.findAll('table', align='right'):
|
||||||
|
img = table.find('img')
|
||||||
|
if img is not None:
|
||||||
|
img.extract()
|
||||||
|
caption = self.tag_to_string(table).strip()
|
||||||
|
div = Tag(soup, 'div')
|
||||||
|
div['style'] = 'text-align:center'
|
||||||
|
div.insert(0, img)
|
||||||
|
div.insert(1, Tag(soup, 'br'))
|
||||||
|
if caption:
|
||||||
|
div.insert(2, NavigableString(caption))
|
||||||
|
table.replaceWith(div)
|
||||||
|
|
||||||
|
return soup
|
||||||
|
|
||||||
return [('Current Issue', articles)]
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user