import re

from calibre.web.feeds.news import BasicNewsRecipe


class RedVoltaireRecipe(BasicNewsRecipe):
    title = u'Red Voltaire'
    __author__ = 'atordo'
    description = u'Red de prensa no alineada, especializada en el an\u00e1lisis de las relaciones internacionales'
    oldest_article = 7
    max_articles_per_feed = 30
    auto_cleanup = False
    no_stylesheets = True
    language = 'es'
    use_embedded_content = False
    remove_javascript = True
    cover_url = u'http://www.voltairenet.org/squelettes/elements/images/logo-voltairenet-org.png'
    masthead_url = u'http://www.voltairenet.org/squelettes/elements/images/logo-voltairenet-org.png'

    preprocess_regexps = [
        (re.compile(r'<title>(?P<titulo>.+)</title>.+<span class="updated" title=".+"><time', re.IGNORECASE | re.DOTALL), lambda match:'</title></head><body><h1>' + match.group('titulo') + '</h1><time'),   # noqa
        (re.compile(
            r'<time datetime=.+pubdate>. (?P<fecha>.+)</time>.+<!------------------- COLONNE TEXTE ------------------->', re.IGNORECASE | re.DOTALL), lambda match:'<small>' + match.group('fecha') + '</small>'), (re.compile(r'<aside>.+', re.IGNORECASE | re.DOTALL), lambda match:'</body></html>')  # noqa
    ]

    extra_css = '''
        img{margin-bottom:0.4em; display:block; margin-left:auto; margin-right:auto}
    '''

    feeds = [
        u'http://www.voltairenet.org/spip.php?page=backend&id_secteur=1110&lang=es']
