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 stuffconz(BasicNewsRecipe):
    title = u'stuff.co.nz'
    language = 'en_NZ'
    __author__ = 'Krittika Goyal'
    oldest_article = 1  # days
    max_articles_per_feed = 25

    keep_only_tags = [
        classes('sics-component__headline sics-component__byline sics-component__story')
    ]
    remove_tags = [
        dict(name=['meta', 'link', 'style']),
        classes('sics-component__sharebar'),
    ]

    remove_stylesheets = True
    feeds = [
        ('Dominion Post',
         'http://www.stuff.co.nz/rss/dominion-post'),
        ('National',
         'http://www.stuff.co.nz/rss/national'),
        ('World',
         'http://www.stuff.co.nz/rss/world'),
        ('Business',
         'http://www.stuff.co.nz/rss/business'),
        ('Technology',
         'http://www.stuff.co.nz/rss/technology'),
        ('Sport',
         'http://www.stuff.co.nz/rss/sport'),
        ('Entertainment',
         'http://www.stuff.co.nz/rss/entertainment'),
        ('Life and Style',
         'http://www.stuff.co.nz/rss/life-style'),

    ]
