#!/usr/bin/env python
# -*- mode: python -*-
# -*- coding: utf-8 -*-

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

from calibre.web.feeds.news import BasicNewsRecipe, classes


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 = 1.2
    no_stylesheets = True
    encoding = 'utf-8'
    use_embedded_content = False
    remove_empty_feeds = True
    compress_news_images = True
    scale_news_images_to_device = True
    ignore_duplicate_articles = {'url'}
    language = 'es_AR'
    publication_type = 'newsportal'
    masthead_url = 'https://www.ambito.com/css-custom/239/images/logo-239-2020v2.svg'
    extra_css = '''
        body{font-family: Roboto, sans-serif}
    '''

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

    keep_only_tags = [
        classes(
            'detail-highlighted-multimedia news-headline__publication-date news-headline__title news-headline__author-wrapper news-headline__article-summary'
        ),
        dict(name='article', attrs={'class': lambda x: x and 'article-body' in x.split()}),
    ]
    remove_tags = [dict(name=['object', 'link', 'embed', 'iframe', 'meta', 'link'])]

    feeds = [
        ('Portada', 'https://www.ambito.com/rss/home.xml'),
        ('Economia', 'https://www.ambito.com/rss/economia.xml'),
        ('Finanzas', 'https://www.ambito.com/rss/finanzas.xml'),
        ('Politica', 'https://www.ambito.com/rss/politica.xml'),
        ('Opinion', 'https://www.ambito.com/rss/opinion.xml'),
        ('Informacion General', 'https://www.ambito.com/rss/informacion-general.xml'),
        ('Mundo', 'https://www.ambito.com/rss/mundo.xml'),
        ('Deportes', 'https://www.ambito.com/rss/deportes.xml'),
        ('Espectaculos', 'https://www.ambito.com/rss/espectaculos.xml'),
        ('Nacional', 'https://www.ambito.com/rss/nacional.xml'),
    ]

    def preprocess_html(self, soup):
        for img in soup.findAll('img', attrs={'data-td-src-property': True}):
            img['src'] = img['data-td-src-property']
        return soup
