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

from calibre.web.feeds.news import BasicNewsRecipe

class Ambito(BasicNewsRecipe):
    title                 = 'Ambito.com'
    __author__            = 'Darko Miletic'
    description           = 'Ambito.com con noticias del Diario Ambito Financiero de Buenos Aires'
    publisher             = 'Editorial Nefir S.A.'
    category              = 'news, politics, economy, finances, Argentina'
    oldest_article        = 2
    no_stylesheets        = True
    encoding              = 'cp1252'
    masthead_url          = 'http://www.ambito.com/img/logo_.jpg'
    use_embedded_content  = False
    language              = 'es_AR'
    publication_type      = 'newsportal'
    extra_css             = """
                                body{font-family: "Trebuchet MS",Verdana,sans-serif}
                                .volanta{font-size: small}
                                .t2_portada{font-size: xx-large; font-family: Georgia,serif; color: #026698}
                            """


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

    keep_only_tags    = [dict(name='div', attrs={'align':'justify'})]
    remove_tags       = [dict(name=['object','link','embed','iframe','meta','link','table','img'])]
    remove_attributes = ['align']

    feeds = [
              (u'Principales Noticias', u'http://www.ambito.com/rss/noticiasp.asp'                         )
             ,(u'Economia'            , u'http://www.ambito.com/rss/noticias.asp?S=Econom%EDa'             )
             ,(u'Politica'            , u'http://www.ambito.com/rss/noticias.asp?S=Pol%EDtica'             )
             ,(u'Informacion General' , u'http://www.ambito.com/rss/noticias.asp?S=Informaci%F3n%20General')
             ,(u'Campo'               , u'http://www.ambito.com/rss/noticias.asp?S=Agro'                   )
             ,(u'Internacionales'     , u'http://www.ambito.com/rss/noticias.asp?S=Internacionales'        )
             ,(u'Deportes'            , u'http://www.ambito.com/rss/noticias.asp?S=Deportes'               )
             ,(u'Espectaculos'        , u'http://www.ambito.com/rss/noticias.asp?S=Espect%E1culos'         )
             ,(u'Tecnologia'          , u'http://www.ambito.com/rss/noticias.asp?S=Tecnolog%EDa'           )
             ,(u'Ambito Nacional'     , u'http://www.ambito.com/rss/noticias.asp?S=Ambito%20Nacional'      )
            ]

    def print_version(self, url):
        return url.replace('/noticia.asp?','/noticias/imprimir.asp?')

    def preprocess_html(self, soup):
        for item in soup.findAll(style=True):
            del item['style']
        for item in soup.findAll('a'):
            str = item.string
            if str is None:
               str = self.tag_to_string(item)
            item.replaceWith(str)
        return soup
