#!/usr/bin/env  python

from calibre.web.feeds.news import BasicNewsRecipe, classes

class OpenMagazine(BasicNewsRecipe):
    title = u'Open Magazine'
    description = 'The weekly current affairs and features magazine.'
    language = 'en_IN'
    __author__ = 'unkn0wn'
    oldest_article = 7  # days
    max_articles_per_feed = 50
    encoding = 'utf-8'
    use_embedded_content = False
    no_stylesheets = True
    remove_attributes = ['style', 'height', 'width'] 
    masthead_url = 'https://openthemagazine.com/wp-content/themes/open/images/logo.png'
    ignore_duplicate_articles = {'url'}
    #extra_css = '#caption-attachment-81294 { font-size: small; font-style: italic; } ' 
    
    keep_only_tags = [
        classes('post-data post-thumb post-meta post-excerp'),
    ]

    remove_tags = [
        classes('top-social menu-social post-author blurb-social button-links'),
    ]
    
    remove_tags_after = [
		classes('post-meta post-excerp'),
	]

    feeds = [
        ('Cover Story','https://openthemagazine.com/cover-story/feed/'),
        ('Columns','https://openthemagazine.com/columns/feed'),
        ('Essays','https://openthemagazine.com/essays/feed'),
        ('Features','https://openthemagazine.com/features/feed'),
        ('Books','https://openthemagazine.com/lounge/books/feed'),
        ('Art & Culture','https://openthemagazine.com/art-culture/feed'),
        ('Cinema','https://openthemagazine.com/cinema/feed'),
        ]

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