#!/usr/bin/env python
# vim:fileencoding=utf-8
from calibre.web.feeds.news import BasicNewsRecipe, classes


class Sonar21(BasicNewsRecipe):
    title = 'Sonar21'
    __author__ = 'unkn0wn'
    oldest_article = 7
    language = 'en_US'
    max_articles_per_feed = 100
    use_embedded_content = False
    masthead_url = 'https://sonar21.com/wp-content/uploads/2024/10/logo_999999_720x216.png'
    cover_url = 'https://sonar21.com/wp-content/uploads/2024/09/sonar21_backplate_vertical.jpg'
    encoding = 'utf-8'
    browser_type = 'webengine'
    no_stylesheets = True
    remove_attributes = ['style', 'height', 'width']
    extra_css = '.entry-meta, .wp-element-caption, .wp-block-image { font-size: small; }'

    keep_only_tags = [classes('entry-header entry-content')]

    remove_tags = [
        dict(name=['iframe', 'svg']),
        classes('addtoany_share_save_container wpd-avatar'),
    ]

    recipe_specific_options = {
        'days': {
            'short': 'Oldest article to download from this news source. In days ',
            'long': 'For example, 0.5, gives you articles from the past 12 hours',
            'default': str(oldest_article),
        },
    }

    def __init__(self, *args, **kwargs):
        BasicNewsRecipe.__init__(self, *args, **kwargs)
        d = self.recipe_specific_options.get('days')
        if d and isinstance(d, str):
            self.oldest_article = float(d)

    feeds = ['https://sonar21.com/feed']
