| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
from __future__ import absolute_import, division, print_function, unicode_literals |
| 4 |
|
| 5 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 6 |
|
| 7 |
|
| 8 |
def classes(classes): |
| 9 |
q = frozenset(classes.split(' ')) |
| 10 |
return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)}) |
| 11 |
|
| 12 |
|
| 13 |
class FoxNews(BasicNewsRecipe): |
| 14 |
title = 'FOX News' |
| 15 |
__author__ = 'Darko Miletic' |
| 16 |
description = 'Breaking News from FOX' |
| 17 |
publisher = 'FOXNews.com' |
| 18 |
category = 'news, breaking news, latest news, current news, world news, national news, USA' |
| 19 |
oldest_article = 2 |
| 20 |
max_articles_per_feed = 200 |
| 21 |
no_stylesheets = True |
| 22 |
encoding = 'utf8' |
| 23 |
use_embedded_content = False |
| 24 |
|
| 25 |
language = 'en_US' |
| 26 |
remove_empty_feeds = True |
| 27 |
extra_css = ''' |
| 28 |
body{font-family: Arial,sans-serif } |
| 29 |
.caption{font-size: x-small} |
| 30 |
.author,.dateline{font-size: small} |
| 31 |
''' |
| 32 |
|
| 33 |
recipe_specific_options = { |
| 34 |
'days': { |
| 35 |
'short': 'Oldest article to download from this news source. In days ', |
| 36 |
'long': 'For example, 0.5, gives you articles from the past 12 hours', |
| 37 |
'default': str(oldest_article), |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
def __init__(self, *args, **kwargs): |
| 42 |
BasicNewsRecipe.__init__(self, *args, **kwargs) |
| 43 |
d = self.recipe_specific_options.get('days') |
| 44 |
if d and isinstance(d, str): |
| 45 |
self.oldest_article = float(d) |
| 46 |
|
| 47 |
conversion_options = {'comment': description, 'tags': category, 'publisher': publisher, 'language': language} |
| 48 |
|
| 49 |
remove_attributes = ['xmlns', 'lang'] |
| 50 |
ignore_duplicate_articles = {'title', 'url'} |
| 51 |
keep_only_tags = [ |
| 52 |
dict(itemprop=['headline', 'articleBody']), |
| 53 |
dict(name='h1'), |
| 54 |
classes('byline author date source article-info article-body featured-image'), |
| 55 |
] |
| 56 |
remove_tags = [ |
| 57 |
classes('featured-video video-container'), |
| 58 |
] |
| 59 |
|
| 60 |
feeds = [ |
| 61 |
('Latest Headlines', 'http://feeds.foxnews.com/foxnews/latest'), |
| 62 |
('National', 'http://feeds.foxnews.com/foxnews/national'), |
| 63 |
('World', 'http://feeds.foxnews.com/foxnews/world'), |
| 64 |
('Politics', 'http://feeds.foxnews.com/foxnews/politics'), |
| 65 |
('Opinion', 'http://feeds.foxnews.com/foxnews/opinion'), |
| 66 |
('Science', 'http://feeds.foxnews.com/foxnews/science'), |
| 67 |
('Technology', 'http://feeds.foxnews.com/foxnews/tech'), |
| 68 |
('Health', 'http://feeds.foxnews.com/foxnews/health'), |
| 69 |
('Lifestyle', 'http://feeds.foxnews.com/foxnews/section/lifestyle'), |
| 70 |
('Travel', 'http://feeds.foxnews.com/foxnews/internal/travel/mixed'), |
| 71 |
] |