
__license__   = 'GPL v3'
__copyright__ = '2008-2011, Darko Miletic <darko.miletic at gmail.com>'
'''
clarin.com
'''

from calibre.web.feeds.news import BasicNewsRecipe

class Clarin(BasicNewsRecipe):
    title                 = 'Clarin'
    __author__            = 'Darko Miletic'
    description           = 'Noticias de Argentina y mundo'
    publisher             = 'Grupo Clarin'
    category              = 'news, politics, Argentina'
    oldest_article        = 2
    max_articles_per_feed = 100
    use_embedded_content  = False
    no_stylesheets        = True
    encoding              = 'utf8'
    delay                 = 1
    language              = 'es_AR'
    publication_type      = 'newspaper'
    INDEX                 = 'http://www.clarin.com'
    masthead_url          = 'http://www.clarin.com/static/CLAClarin/images/logo-clarin-print.jpg'
    extra_css             = """ 
                               body{font-family: Arial,Helvetica,sans-serif} 
                               h2{font-family: Georgia,serif; font-size: xx-large} 
                               .hora{font-weight:bold} 
                               .hd p{font-size: small} 
                               .nombre-autor{color: #0F325A} 
                            """

    conversion_options = {
                          'comment'  : description
                        , 'tags'     : category
                        , 'publisher': publisher
                        , 'language' : language
                        }

    keep_only_tags    = [dict(attrs={'class':['hd','mt']})]
    remove_tags       = [dict(name=['meta','base','link'])]
    remove_attributes = ['lang','_mce_bogus']

    feeds = [
               (u'Pagina principal', u'http://www.clarin.com/rss/'             )
              ,(u'Politica'        , u'http://www.clarin.com/rss/politica/'    )
              ,(u'Deportes'        , u'http://www.clarin.com/rss/deportes/'    )
              ,(u'Economia'        , u'http://www.clarin.com/economia/'        )
              ,(u'Mundo'           , u'http://www.clarin.com/rss/mundo/'       )
              ,(u'Espectaculos'    , u'http://www.clarin.com/rss/espectaculos/')
              ,(u'Sociedad'        , u'http://www.clarin.com/rss/sociedad/'    )
              ,(u'Ciudades'        , u'http://www.clarin.com/rss/ciudades/'    )
              ,(u'Policiales'      , u'http://www.clarin.com/rss/policiales/'  )
              ,(u'Internet'        , u'http://www.clarin.com/rss/internet/'    )
              ,(u'Ciudades'        , u'http://www.clarin.com/rss/ciudades/'    )
            ]

    
    def get_article_url(self, article):
        return article.get('guid',  None)
    
    def print_version(self, url):
        return url + '?print=1'

    def get_cover_url(self):
        cover_url = None
        soup = self.index_to_soup(self.INDEX)
        cover_item = soup.find('div',attrs={'class':'bb-md bb-md-edicion_papel'})
        if cover_item:
           ap = cover_item.find('a',attrs={'href':'/edicion-impresa/'})
           if ap:
              cover_url = self.INDEX + ap.img['src']
        return cover_url

