| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
__license__ = 'GPL v3' |
| 4 |
__copyright__ = '2009-2010, Darko Miletic <darko.miletic at gmail.com>' |
| 5 |
|
| 6 |
''' |
| 7 |
english.aljazeera.net |
| 8 |
''' |
| 9 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 10 |
|
| 11 |
|
| 12 |
class AlJazeera(BasicNewsRecipe): |
| 13 |
title = 'Al Jazeera in English' |
| 14 |
__author__ = 'Darko Miletic' |
| 15 |
description = 'News from Middle East' |
| 16 |
language = 'en' |
| 17 |
publisher = 'Al Jazeera' |
| 18 |
category = 'news, politics, middle east' |
| 19 |
delay = 1 |
| 20 |
oldest_article = 2 |
| 21 |
max_articles_per_feed = 100 |
| 22 |
no_stylesheets = True |
| 23 |
use_embedded_content = False |
| 24 |
extra_css = ''' |
| 25 |
body{font-family: Arial,sans-serif} |
| 26 |
''' |
| 27 |
conversion_options = {'comment': description, 'tags': category, 'publisher': publisher, 'language': language} |
| 28 |
keep_only_tags = [ |
| 29 |
classes('article-header article-featured-image wysiwyg--all-content'), |
| 30 |
] |
| 31 |
|
| 32 |
remove_tags = [ |
| 33 |
dict(name=['object', 'link', 'table', 'meta', 'base', 'iframe', 'embed']), |
| 34 |
] |
| 35 |
|
| 36 |
recipe_specific_options = { |
| 37 |
'days': { |
| 38 |
'short': 'Oldest article to download from this news source. In days ', |
| 39 |
'long': 'For example, 0.5, gives you articles from the past 12 hours', |
| 40 |
'default': str(oldest_article), |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
def __init__(self, *args, **kwargs): |
| 45 |
BasicNewsRecipe.__init__(self, *args, **kwargs) |
| 46 |
d = self.recipe_specific_options.get('days') |
| 47 |
if d and isinstance(d, str): |
| 48 |
self.oldest_article = float(d) |
| 49 |
|
| 50 |
feeds = [('Al Jazeera English', 'http://www.aljazeera.com/xml/rss/all.xml')] |
| 51 |
|
| 52 |
def get_article_url(self, article): |
| 53 |
artlurl = article.get('link', None) |
| 54 |
return artlurl |
| 55 |
|
| 56 |
def preprocess_html(self, soup): |
| 57 |
for item in soup.findAll(style=True): |
| 58 |
del item['style'] |
| 59 |
for item in soup.findAll(face=True): |
| 60 |
del item['face'] |
| 61 |
for alink in soup.findAll('a'): |
| 62 |
if alink.string is not None: |
| 63 |
tstr = alink.string |
| 64 |
alink.replaceWith(tstr) |
| 65 |
return soup |