| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
__license__ = 'GPL v3' |
| 4 |
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>' |
| 5 |
''' |
| 6 |
Profile to download CNN |
| 7 |
''' |
| 8 |
|
| 9 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 10 |
|
| 11 |
|
| 12 |
class CNN(BasicNewsRecipe): |
| 13 |
title = 'CNN' |
| 14 |
description = 'Global news' |
| 15 |
timefmt = ' [%d %b %Y]' |
| 16 |
__author__ = 'Kovid Goyal' |
| 17 |
language = 'en_US' |
| 18 |
|
| 19 |
no_stylesheets = True |
| 20 |
use_embedded_content = False |
| 21 |
oldest_article = 2 |
| 22 |
ignore_duplicate_articles = {'url'} |
| 23 |
max_articles_per_feed = 25 |
| 24 |
remove_attributes = ['style', 'height', 'width'] |
| 25 |
keep_only_tags = [ |
| 26 |
classes('headline__wrapper headline__sub-container article__main'), |
| 27 |
] |
| 28 |
remove_tags = [classes('video-inline_carousel')] |
| 29 |
|
| 30 |
recipe_specific_options = { |
| 31 |
'days': { |
| 32 |
'short': 'Oldest article to download from this news source. In days ', |
| 33 |
'long': 'For example, 0.5, gives you articles from the past 12 hours', |
| 34 |
'default': str(oldest_article), |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
def __init__(self, *args, **kwargs): |
| 39 |
BasicNewsRecipe.__init__(self, *args, **kwargs) |
| 40 |
d = self.recipe_specific_options.get('days') |
| 41 |
if d and isinstance(d, str): |
| 42 |
self.oldest_article = float(d) |
| 43 |
|
| 44 |
feeds = [ |
| 45 |
('Top News', 'http://rss.cnn.com/rss/cnn_topstories.rss'), |
| 46 |
('World', 'http://rss.cnn.com/rss/cnn_world.rss'), |
| 47 |
('U.S.', 'http://rss.cnn.com/rss/cnn_us.rss'), |
| 48 |
# ('Sports', 'http://rss.cnn.com/rss/si_topstories.rss'), |
| 49 |
('Business', 'http://rss.cnn.com/rss/money_latest.rss'), |
| 50 |
('Politics', 'http://rss.cnn.com/rss/cnn_allpolitics.rss'), |
| 51 |
('Law', 'http://rss.cnn.com/rss/cnn_law.rss'), |
| 52 |
('Technology', 'http://rss.cnn.com/rss/cnn_tech.rss'), |
| 53 |
('Science & Space', 'http://rss.cnn.com/rss/cnn_space.rss'), |
| 54 |
('Health', 'http://rss.cnn.com/rss/cnn_health.rss'), |
| 55 |
('Entertainment', 'http://rss.cnn.com/rss/cnn_showbiz.rss'), |
| 56 |
('Education', 'http://rss.cnn.com/rss/cnn_education.rss'), |
| 57 |
('Offbeat', 'http://rss.cnn.com/rss/cnn_offbeat.rss'), |
| 58 |
('Most Popular', 'http://rss.cnn.com/rss/cnn_mostpopular.rss'), |
| 59 |
] |
| 60 |
|
| 61 |
def get_article_url(self, article): |
| 62 |
ans = BasicNewsRecipe.get_article_url(self, article) |
| 63 |
ans = ans.partition('?')[0] |
| 64 |
if '.com/videos/' in ans: |
| 65 |
ans = None |
| 66 |
return ans |
| 67 |
|
| 68 |
def get_masthead_url(self): |
| 69 |
masthead = 'http://i.cdn.turner.com/cnn/.element/img/3.0/global/header/intl/hdr-globe-central.gif' |
| 70 |
br = BasicNewsRecipe.get_browser(self) |
| 71 |
try: |
| 72 |
br.open(masthead) |
| 73 |
except Exception: |
| 74 |
self.log('\nCover unavailable') |
| 75 |
masthead = None |
| 76 |
return masthead |
| 77 |
|
| 78 |
def preprocess_html(self, soup): |
| 79 |
for img in soup.findAll('img', attrs={'src': lambda x: x and x.endswith('.svg')}): |
| 80 |
img.extract() |
| 81 |
return soup |