"""
Fetch Magyar Nemzet
"""

import re

from calibre.web.feeds.news import BasicNewsRecipe


class mn(BasicNewsRecipe):
    title = 'Magyar Nemzet'
    description = ''
    __author__ = 'bubak'
    use_embedded_content = False
    oldest_article = 2
    max_articles_per_feed = 40
    no_stylesheets = True
    language = 'hu'
    simultaneous_downloads = 5

    remove_javascript = True
    cover_url = 'https://magyarnemzet.hu/assets/images/logo-mno-dark.svg'

    feeds = [('MNO hírek2', 'https://magyarnemzet.hu/publicapi/hu/rss/magyar_nemzet/articles')]

    extra_css = '''
                    '''

    def preprocess_html(self, soup):
        h2 = soup.find('h2')
        h2.name = 'badH2'
        return soup

    preprocess_regexps = [(re.compile(r'<a\s[^>]*>(.*?)</a>', re.DOTALL | re.IGNORECASE), lambda match: match.group(1))]

    remove_attributes = []
    remove_tags_before = dict(name='h3', attrs={'class': ['cikkcim']})
    remove_tags_after = dict(name='mno-promo-block')
    remove_tags = [
        dict(name='div', attrs={'class': ['adbox ad_cikk_kozepre']}),
        dict(name='div', attrs={'class': ['cikk_share_box clr', 'sidebar', 'breaking']}),
        dict(name='div', attrs={'class': ['cikk-cimkek', 'colwrp', 'article-cikkboxes clearfix']}),
        dict(name='div', attrs={'class': ['author', 'article-data', 'info-line', 'dossier-link-wrapper']}),
        dict(name='div', attrs={'id': ['menu', 'article-right-col', 'header']}),
        dict(name='header'),
        dict(name='app-breadcrumb'),
        dict(name='mno-tag-list'),
        dict(name='figcaption'),
        dict(name='app-comment-section'),
        dict(name='div', attrs={'class': ['cikk_video_box box clr', 'cikkblock']}),
        dict(name='article', attrs={'class': ['article-recommender']}),
        dict(name='a', attrs={'href': ['http://www.mno.hu/sorolo', '/rovat/keresztrejtveny']}),
        dict(name='app-recommendation-block'),
        dict(name='mno-external-recommendation-block'),
        dict(name='mno-opinion-newsletter-box'),
        dict(name='mno-promo-block'),
        dict(name='mno-tag-list'),
        dict(name='div', attrs={'class': ['print']}),
    ]
