from calibre.web.feeds.news import BasicNewsRecipe


class goonews(BasicNewsRecipe):
    __author__     = 'Douglas Delgado'
    title          = u'Diario Extra'
    publisher      = 'Sociedad Periodistica Extra Limitada'
    description    = 'Diario de circulacion nacional de Costa Rica.'
    category       = 'Spanish, Entertainment'
    masthead_url   = 'http://www.diarioextra.com/img/apariencia/logo.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          = [(u'Nacionales',
                       u'http://www.diarioextra.com/includes/rss_text.php?id=1'),
                      (u'Internacionales',
                       u'http://www.diarioextra.com/includes/rss_text.php?id=2'),
                      (u'Sucesos',
                       u'http://www.diarioextra.com/includes/rss_text.php?id=3'),
                      (u'Deportes',
                       u'http://www.diarioextra.com/includes/rss_text.php?id=6'),
                      (u'Espectaculos',
                       u'http://www.diarioextra.com/includes/rss_text.php?id=7'),
                      (u'Opinion',
                       u'http://www.diarioextra.com/includes/rss_text.php?id=4')]

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

    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;}
                '''
