from calibre.web.feeds.news import BasicNewsRecipe


def classes(classes):
    q = frozenset(classes.split(' '))
    return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)})


class WinnipegFreePress(BasicNewsRecipe):
    title = 'Winnipeg Free Press'
    __author__ = 'buyo'
    description = 'News from Winnipeg, Manitoba, Canada'
    oldest_article = 1
    max_articles_per_feed = 15
    category = 'News, Winnipeg, Canada'
    no_stylesheets = True
    encoding = 'UTF-8'
    remove_javascript = True
    use_embedded_content = False
    language = 'en_CA'
    extra_css = '''
    .factbox { border: solid 2px; padding: 1rem }
    '''

    feeds = [
        ('Breaking News', 'http://www.winnipegfreepress.com/rss?path=/breakingnews'),
        ('Local News', 'http://www.winnipegfreepress.com/rss?path=/local'),
        ('Breaking Business News', 'http://www.winnipegfreepress.com/rss?path=/business/finance'),
        ('Business', 'http://www.winnipegfreepress.com/rss?path=/business'),
        ('Editorials', 'http://www.winnipegfreepress.com/rss?path=/opinion/editorials'),
        ('Views from the West', 'http://www.winnipegfreepress.com/rss?path=/opinion/westview'),
        ('Life & Style', 'http://www.winnipegfreepress.com/rss?path=/life'),
        ('Food & Drink', 'http://www.winnipegfreepress.com/rss?path=/life/food'),
    ]

    keep_only_tags = [classes('article-title topphoto storycontent')]
    remove_tags = [dict(name='button')]
