#!/usr/bin/env python
# vim:fileencoding=utf-8

from calibre.web.feeds.news import BasicNewsRecipe


class Sobaka(BasicNewsRecipe):
    title = '\u0421\u043e\u0431\u0430\u043a\u0430.ru'
    __author__ = 'bugmen00t'
    description = (
        '\u0416\u0443\u0440\u043d\u0430\u043b \u043e \u043b\u044e\u0434\u044f\u0445 \u0432 \u041f\u0435\u0442\u0435\u0440\u0431\u0443\u0440\u0433\u0435'  # noqa: E501
    )
    publisher = '\u041e\u041e\u041e \u00ab\u0416\u0443\u0440\u043d\u0430\u043b\u044b \u0438 \u0441\u0430\u0439\u0442\u044b "\u0424\u0430\u0431\u0440\u0438\u043a\u0430 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 "\u0422\u043e\u0447\u043a\u0430 \u0420\u0443"\u00bb'  # noqa: E501
    category = 'magazine'
    cover_url = 'https://static.sobaka.ru/images/post/00/04/31/21/_rotator.jpg'
    language = 'ru'
    no_stylesheets = False
    remove_javascript = False
    auto_cleanup = False
    oldest_article = 7
    max_articles_per_feed = 50

    remove_tags_before = dict(name='div', attrs={'class': 'b-post-view__head'})

    remove_tags_after = dict(name='div', attrs={'class': 'b-post-view__foot'})

    remove_tags = [
        dict(name='div', attrs={'class': 'b-post-view__telegram-promo'}),
        dict(name='div', attrs={'class': 'b-post-view__tgb'}),
        dict(name='div', attrs={'id': 'comments'}),
        dict(name='div', attrs={'class': 'b-post-view__section'}),
        dict(name='div', attrs={'class': 'b-post-view__share'}),
        dict(name='div', attrs={'class': 'b-post-view__details-col b-post-view__details-col--w1'}),
    ]

    feeds = [('\u041d\u043e\u0432\u043e\u0441\u0442\u0438', 'https://www.sobaka.ru/rss/news.xml')]

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