mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-09-29 15:31:08 -04:00
63 lines
2.5 KiB
Python
63 lines
2.5 KiB
Python
#!/usr/bin/env python2
|
|
from __future__ import unicode_literals
|
|
__license__ = 'GPL v3'
|
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|
'''
|
|
theatlantic.com
|
|
'''
|
|
import re
|
|
from calibre.web.feeds.news import BasicNewsRecipe
|
|
|
|
class TheAtlantic(BasicNewsRecipe):
|
|
|
|
title = 'The Atlantic'
|
|
__author__ = 'Kovid Goyal'
|
|
description = 'Current affairs and politics focussed on the US'
|
|
INDEX = 'http://www.theatlantic.com/magazine/toc/0/'
|
|
language = 'en'
|
|
encoding = 'utf-8'
|
|
|
|
keep_only_tags = [
|
|
{'attrs':{'class':['article-header', 'article-body', 'article-magazine']}},
|
|
]
|
|
remove_tags = [
|
|
{'name': ['meta', 'link', 'noscript']},
|
|
{'attrs':{'class':['offset-wrapper', 'ad-boxfeatures-wrapper']}},
|
|
{'attrs':{'class':lambda x: x and 'article-tools' in x}},
|
|
{'src':lambda x:x and 'spotxchange.com' in x},
|
|
]
|
|
no_stylesheets = True
|
|
preprocess_regexps = [
|
|
(re.compile(r'<script\b.+?</script>', re.DOTALL), lambda m: ''),
|
|
(re.compile(r'^.*<html', re.DOTALL|re.IGNORECASE), lambda m: '<html'),
|
|
]
|
|
|
|
def print_version(self, url):
|
|
return url + '?single_page=true'
|
|
|
|
def parse_index(self):
|
|
soup = self.index_to_soup(self.INDEX)
|
|
col = soup.find(attrs={'class':'contentColumn singleContent'})
|
|
current_section, current_articles = None, []
|
|
feeds = []
|
|
for tag in col.findAll(name=['h2', 'li'], attrs={'class':['section-header', 'top-item', 'river-item']}):
|
|
if tag.name == 'h2':
|
|
if current_section and current_articles:
|
|
feeds.append((current_section, current_articles))
|
|
current_section = self.tag_to_string(tag).capitalize()
|
|
current_articles = []
|
|
self.log('Found section:', current_section)
|
|
elif current_section:
|
|
a = tag.find('a', href=True)
|
|
if a is not None:
|
|
title, url = self.tag_to_string(a), a['href']
|
|
if title and url:
|
|
p = tag.find('p', attrs={'class':'river-dek'})
|
|
desc = self.tag_to_string(p) if p is not None else ''
|
|
current_articles.append({'title':title, 'url':url, 'description':desc})
|
|
self.log('\tArticle:', title, '[%s]' % url)
|
|
self.log('\t\t', desc)
|
|
if current_section and current_articles:
|
|
feeds.append((current_section, current_articles))
|
|
return feeds
|