from calibre.web.feeds.news import BasicNewsRecipe


class crnews(BasicNewsRecipe):
    __author__ = 'Douglas Delgado'
    title = 'La Nacion Costa Rica'
    publisher = 'GRUPO NACION GN, S. A.'
    description = (
        'Diario de circulacion nacional de Costa Rica. Recipe creado por Douglas Delgado (doudelgado@gmail.com) para su uso con Calibre por Kovid Goyal'  # noqa: E501
    )
    category = 'Spanish, Entertainment'
    masthead_url = 'http://www.nacion.com/App_Themes/nacioncom/Images/logo_nacioncom.png'

    oldest_article = 7
    delay = 1
    max_articles_per_feed = 100
    auto_cleanup = True
    encoding = 'utf-8'
    language = 'es_CR'
    use_embedded_content = False
    remove_empty_feeds = True
    remove_javascript = True
    no_stylesheets = True

    feeds = [
        ('Portada', 'http://www.nacion.com/rss/'),
        ('Ultima Hora', 'http://www.nacion.com/rss/latest/'),
        ('Nacionales', 'http://www.nacion.com/rss/nacional/'),
        ('Entretenimiento', 'http://www.nacion.com/rss/ocio/'),
        ('Sucesos', 'http://www.nacion.com/rss/sucesos/'),
        ('Deportes', 'http://www.nacion.com/rss/deportes/'),
        ('Internacionales', 'http://www.nacion.com/rss/mundo/'),
        ('Economia', 'http://www.nacion.com/rss/economia/'),
        ('Vivir', 'http://www.nacion.com/rss/vivir/'),
        ('Tecnologia', 'http://www.nacion.com/rss/tecnologia/'),
        ('Opinion', 'http://www.nacion.com/rss/opinion/'),
    ]

    def get_cover_url(self):
        index = 'http://kiosko.net/cr/np/cr_nacion.html'
        soup = self.index_to_soup(index)
        for image in soup.findAll('img', src=True):
            if image['src'].endswith('cr_nacion.750.jpg'):
                return image['src']
        return None

    def get_article_url(self, article):
        url = article.get('guid', None)
        return url

    extra_css = '''
                    h1{font-family:Arial,Helvetica,sans-serif; font-weight:bold;font-size:30px;}
                    h2{font-family:Arial,Helvetica,sans-serif; font-weight:normal; font-style:italic; font-size:18px;}
                '''
