import re

from calibre.web.feeds.news import BasicNewsRecipe


class AdvancedUserRecipe1289939440(BasicNewsRecipe):
    __author__ = 'FunThomas'
    title = 'Root.cz'
    description = 'Zprávičky a články z Root.cz'
    publisher = 'Internet Info, s.r.o'
    oldest_article = 2  # max stari clanku ve dnech
    max_articles_per_feed = 50  # max pocet clanku na feed

    feeds = [('Články', 'http://www.root.cz/rss/clanky/'), ('Zprávičky', 'http://www.root.cz/rss/zpravicky/')]

    publication_type = 'magazine'
    language = 'cs'
    no_stylesheets = True
    remove_javascript = True
    cover_url = 'http://i.iinfo.cz/urs/logo-root-bila-oranzova-cerna-111089527143118.gif'

    remove_attributes = ['width', 'height', 'href']  # ,'href'
    keep_only_tags = [
        dict(name='h1'),
        dict(name='a', attrs={'class': 'author'}),
        dict(name='p', attrs={'class': 'intro'}),
        dict(name='div', attrs={'class': 'urs'}),
    ]

    preprocess_regexps = [
        (re.compile(r'<p class="perex[^"]*">[^<]*<img[^>]*>', re.DOTALL), lambda match: '<p class="intro">'),
        (
            re.compile(
                '<h3><a name="tucnak">Tričko tučňák.*</body>',  # noqa: RUF039
                re.DOTALL,
            ),
            lambda match: '<!--deleted-->',
        ),
    ]

    extra_css = '''
                h1 {font-size:130%; font-weight:bold}
                h3 {font-size:111%; font-weight:bold}
              '''
