#!/usr/bin/env python2
__license__ = 'GPL v3'
__author__ = 'Daniele Forsi'

from calibre.web.feeds.recipes import BasicNewsRecipe


class LeScienze(BasicNewsRecipe):
    title = 'Le Scienze'
    description = 'Edizione italiana di Scientific American'
    publication_type = 'magazine'
    language = 'it'
    conversion_options = {
        'publisher': 'Le Scienze S.p.A.',
        'tags': 'science',
    }

    INDEX = 'http://www.lescienze.it/utility/2011/10/17/news/lista_rss-589690/'
    masthead_url = 'http://www.lescienze.it/static/images/logo-le-scienze.png'
    no_stylesheets = True
    extra_css = '''
    .img-left,.img-right{font-style:italic;font-size:75%;padding:1em;margin:auto;}
    .summary{font-style:italic;font-size:120%;}
    '''
    keep_only_tags = [
        dict(name='article', attrs={'class': 'main-article'}),
    ]
    remove_tags = [
        dict(attrs={'class': [
            'adv adv-middle',
            'colsx',
            'correlati',
            'social-toolbar-foot',
            'tags',
        ]}),
    ]
    remove_empty_feeds = True

    def get_feeds(self):
        soup = self.index_to_soup(self.INDEX)
        feeds = []

        for link in soup.findAll('a'):
            href = link.get('href')
            if href.endswith('.xml'):
                title = link.string
                feeds.append((title, href))

        return feeds
