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 JerusalemPost(BasicNewsRecipe):

    title = 'Jerusalem Post'
    description = 'News from Israel and the Middle East'
    use_embedded_content = False
    language = 'en'
    keep_only_tags = [
        classes('margin-container-body article-title article-subline article-inner-content-breaking-news'),
    ]
    remove_tags = [
        classes('share-buttons hide-for-premium'),
    ]
    remove_attributes = ['style']
    no_stylesheets = True

    __author__ = 'Kovid Goyal'
    max_articles_per_feed = 10
    no_stylesheets = True

    def get_browser(self):
        return BasicNewsRecipe.get_browser(self, user_agent='common_words/based')

    feeds = [
        ('Top Stories', 'https://www.jpost.com/Rss/RssFeedsHeadlines.aspx'),
        ('Arab Israeli Conflict', 'https://www.jpost.com/rss/rssfeedsarabisraeliconflict.aspx'),
        ('US Politics', 'https://www.jpost.com/rss/rssfeedsamerican-politics'),
        ('Israel News', 'https://www.jpost.com/rss/rssfeedsisraelnews.aspx'),
        (
            'Middle East News',
            'https://www.jpost.com/rss/rssfeedsmiddleeastnews.aspx'
        ),
        ('International News', 'https://www.jpost.com/rss/rssfeedsinternational'),
        ('Opinion', 'https://www.jpost.com/Rss/RssFeedsOpinion.aspx'),
    ]
