import re

from calibre.web.feeds.news import BasicNewsRecipe


class ElMundoTodayRecipe(BasicNewsRecipe):
    title = 'El Mundo Today'
    description = 'La actualidad del ma\u00f1ana'
    category = 'Noticias, humor'
    cover_url = 'http://www.elmundotoday.com/wp-content/themes/EarthlyTouch/images/logo.png'
    oldest_article = 15
    max_articles_per_feed = 60
    auto_cleanup = False
    no_stylesheets = True
    remove_javascript = True
    language = 'es'
    use_embedded_content = False
    publication_type = 'blog'

    preprocess_regexps = [
        (re.compile(r'</title>.*<!--Begin Article Single-->', re.DOTALL), lambda match: '</title></head><body>'),
        (re.compile(r'<img alt="" src="http://www.elmundotoday.com/wp-content/themes/emt/images/otrassecciones-line.gif">'), lambda match: ''),
        (re.compile(r'<div style="clear: both;"></div>.*</body>', re.DOTALL), lambda match: '</body>'),
    ]

    keep_only_tags = [dict(name='div', attrs={'class': 'post-wrapper '})]

    remove_tags = [dict(name='div', attrs={'class': 'social4i'}), dict(name='span', attrs={'class': 'num-comentarios'})]

    remove_attributes = ['href', 'title', 'alt']

    extra_css = '''
        .antetitulo{font-variant:small-caps; font-weight:bold} .articleinfo{font-size:small}
        img{margin-bottom:0.4em; display:block; margin-left:auto; margin-right:auto}
    '''

    feeds = [('El Mundo Today', 'http://www.elmundotoday.com/feed/')]
