#!/usr/pkg/bin/python3.13
# -*- coding: utf-8 -*-

__license__ = 'GPL v3'
__copyright__ = 'benages, based on elperidicodearagon.com by desUBIKado'
__author__ = 'benages'
__description__ = 'Daily newspaper from Castellón'
__version__ = 'v0.10'
__date__ = '07, March 2019'
'''
elperiodicomediterraneo.com
'''
from calibre.web.feeds.news import BasicNewsRecipe


class elperiodicomediterraneo(BasicNewsRecipe):
    title = u'El Periódico Mediterráneo'
    __author__ = u'benages'
    description = u'Noticias desde Castellón'
    publisher = u'elperiodicomediterraneo.com'
    category = u'news, politics, Spain, Castellón'
    oldest_article = 1
    delay = 1
    max_articles_per_feed = 100
    no_stylesheets = True
    use_embedded_content = False
    language = 'es'
    masthead_url = 'http://pdf.elperiodicomediterraneo.com/img/logotipo.gif'
    encoding = 'iso-8859-1'
    remove_empty_feeds = True
    remove_javascript = True

    # The index of feeds is in https://www.elperiodicomediterraneo.com/info/rss.php
    feeds = [
        (u'Portada', u'https://est.zetaestaticos.com/mediterraneo/rss/portada_es.xml'),
        (u'Ultima hora', u'https://est.zetaestaticos.com/mediterraneo/rss/ultimahora_es.xml'),
        (u'Castell\xf3n', u'https://est.zetaestaticos.com/mediterraneo/rss/2_es.xml'),
        (u'Vila-Real', u'https://est.zetaestaticos.com/mediterraneo/rss/102_es.xml'),
        (u'Comarcas', u'https://est.zetaestaticos.com/mediterraneo/rss/10_es.xml'),
        (u'Comunitat', u'https://est.zetaestaticos.com/mediterraneo/rss/230_es.xml'),
        (u'Espa\xf1a', u'https://est.zetaestaticos.com/mediterraneo/rss/3_es.xml'),
        (u'Opini\xf3n', u'https://est.zetaestaticos.com/mediterraneo/rss/103_es.xml'),
        (u'Internacional', u'https://est.zetaestaticos.com/mediterraneo/rss/4_es.xml'),
        (u'Econom\xeda', u'https://est.zetaestaticos.com/mediterraneo/rss/5_es.xml'),
        (u'Deportes', u'https://est.zetaestaticos.com/mediterraneo/rss/7_es.xml'),
        (u'Villarreal', u'https://est.zetaestaticos.com/mediterraneo/rss/288_es.xml'),
        (u'Castell\xf3n CF', u'https://est.zetaestaticos.com/mediterraneo/rss/319_es.xml'),
        (u'Sucesos', u'https://est.zetaestaticos.com/mediterraneo/rss/105_es.xml'),
        (u'Sociedad', u'https://est.zetaestaticos.com/mediterraneo/rss/106_es.xml'),
        (u'Espectaculos', u'https://est.zetaestaticos.com/mediterraneo/rss/107_es.xml'),
        (u'Televisi\xf3n', u'https://est.zetaestaticos.com/mediterraneo/rss/324_es.xml'),
    ]

    remove_tags_before = dict(name='div', attrs={'class': 'Pagina'})
    remove_tags_after = dict(name='div', attrs={'class': 'ComentariosNew'})

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

    remove_tags = [
        dict(
            name='nav',
            attrs={'class': ['Compartir', 'HerramientasConversacion Herramientas']}
        ),
        dict(name='h5', attrs={'class': ['CintilloBox']}),
        dict(
            name='div',
            attrs={
                'class': [
                    'BoxMenu BoxMenuConFoto', 'BxGalerias', 'ConStick',
                    'HerramientasComentarioNew Herramientas', 'NumeroComentarioNew'
                ]
            }
        ),
        dict(
            name='div',
            attrs={
                'class': [
                    'BoxPestanas', 'Box', 'ColumnaDerecha',
                    'NoticiasRelacionadasDeNoticia',
                    'CintilloNoticiasRelacionadasDeNoticia'
                ]
            }
        ),
        dict(name='a', attrs={'class': ['IrA BotonLink']})
    ]

    # Recuperamos la portada de papel (la imagen format=1 tiene mayor resolucion)

    def get_cover_url(self):
        index = 'http://pdf.elperiodicomediterraneo.com/edicion.php'
        soup = self.index_to_soup(index)
        for image in soup.findAll('img', src=True):
            if image['src'].startswith('/funciones/img-public.php?key='):
                return 'http://pdf.elperiodicomediterraneo.com' + image['src']
        return None

    extra_css = '''
                    h1 {font-family:Arial,Helvetica,sans-serif; font-weight:bold;font-size:28px;}
                    h2 {font-family:Arial,Helvetica,sans-serif; font-style:italic;font-size:14px;color:#4D4D4D;}
                    h3 {font-family:Arial,Helvetica,sans-serif; font-weight:bold;font-size:18px;}
                '''
