# -*- coding: utf-8 -*-
from calibre.web.feeds.news import BasicNewsRecipe


class AntywebRecipe(BasicNewsRecipe):
    encoding = 'utf-8'
    __license__ = 'GPL v3'
    __author__ = 'Artur Stachecki <artur.stachecki@gmail.com>, adrianf0'
    language = 'pl'
    version = 1
    title = 'Antyweb'
    category = 'News'
    description = 'Blog o internecie i nowych technologiach'
    cover_url = ''
    remove_empty_feeds = True
    auto_cleanup = False
    no_stylesheets = True
    use_embedded_content = False
    oldest_article = 7
    max_articles_per_feed = 100
    remove_javascript = True
    simultaneous_downloads = 10
    # zignoruj zduplikowane artykuły o takich samych tytułach LUB adresach
    ignore_duplicate_articles = {'title', 'url'}
    scale_news_images = True
    conversion_options = {
        'tags': 'news, aplikacje mobilne, Android, iOS, Windows Phone ',
        'smarten_punctuation': True,
        'publisher': 'AntyWeb',
    }  # opcje konwersji.

    keep_only_tags = []
    keep_only_tags.append(dict(name='h1'))
    keep_only_tags.append(dict(name='section', attrs={'class': 'article'}))
    remove_tags = []
    remove_tags.append(dict(name='div', attrs={'class': 'ac-footer group'}))

    feeds = [
        ('News', 'http://feeds.feedburner.com/antyweb'),
        ('Felietony', 'http://feeds.feedburner.com/AntywebFelietony'),
        ('Apple', 'http://feeds.feedburner.com/AntywebApple'),
        ('Gry', 'http://feeds.feedburner.com/AntywebGry'),
        ('Mobile', 'http://feeds.feedburner.com/AntywebMobile'),
        ('Startups', 'http://feeds.feedburner.com/AntywebStartups'),
        ('Google', 'http://feeds.feedburner.com/AntywebGoogle'),
        ('Microsoft', 'http://feeds.feedburner.com/AntywebMicrosoft'),
    ]

    def preprocess_html(self, soup):
        for alink in soup.findAll('a'):
            if alink.string is not None:
                tstr = alink.string
                alink.replaceWith(tstr)
        return soup
