#!/usr/bin/env python

"""
Nautilus Magazine recipe for Calibre
Grouped by subject category.
"""

from calibre.web.feeds.news import BasicNewsRecipe


class Nautilus(BasicNewsRecipe):
    title = 'Nautilus Magazine'
    __author__ = 'Ludoviko'
    language = 'en_US'

    description = 'Nautilus is a science magazine exploring science, culture, technology, philosophy, nature, and society.'

    publisher = 'Nautilus'
    category = 'Science, Technology, Culture'

    # Only include articles published during the last 30 days.
    oldest_article = 30

    # Maximum number of articles in each category.
    max_articles_per_feed = 20

    # Remove categories that have no recent articles.
    remove_empty_feeds = True
    ignore_duplicate_articles = {'url'}
    # Follow each RSS entry to the full Nautilus article page.
    use_embedded_content = False

    # Let Calibre identify and clean the main article text.
    auto_cleanup = True

    # Simplify the formatting for ebook readers.
    no_stylesheets = True
    remove_javascript = True

    # Allow images to resize correctly.
    remove_attributes = ['height', 'width']

    masthead_url = 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Nautilus.svg/640px-Nautilus.svg.png'

    extra_css = '''
        body {
            line-height: 1.45;
        }

        h1 {
            line-height: 1.15;
        }

        blockquote {
            margin: 1em 2em;
            font-style: italic;
        }

        figcaption {
            font-size: 0.85em;
            text-align: center;
        }
    '''

    feeds = [
        (
            'ANTHROPOLOGY',
            'https://nautil.us/category/anthropology/feed',
        ),
        (
            'ENVIRONMENT',
            'https://nautil.us/category/environment/feed',
        ),
        (
            'HEALTH',
            'https://nautil.us/category/health/feed',
        ),
        (
            'PALEONTOLOGY',
            'https://nautil.us/category/paleontology/feed',
        ),
        (
            'TECHNOLOGY',
            'https://nautil.us/category/technology/feed',
        ),
        (
            'ARTS',
            'https://nautil.us/category/arts/feed',
        ),
        (
            'EVOLUTION',
            'https://nautil.us/category/evolution/feed',
        ),
        (
            'HISTORY',
            'https://nautil.us/category/history/feed',
        ),
        (
            'PHILOSOPHY',
            'https://nautil.us/category/philosophy/feed',
        ),
        (
            'ZOOLOGY',
            'https://nautil.us/category/zoology/feed',
        ),
        (
            'ASTRONOMY',
            'https://nautil.us/category/astronomy/feed',
        ),
        (
            'GENERAL',
            'https://nautil.us/category/general/feed',
        ),
        (
            'MATH',
            'https://nautil.us/category/math/feed',
        ),
        (
            'PHYSICS',
            'https://nautil.us/category/physics/feed',
        ),
        (
            'COMMUNICATION',
            'https://nautil.us/category/communication/feed',
        ),
        (
            'GENETICS',
            'https://nautil.us/category/genetics/feed',
        ),
        (
            'MICROBIOLOGY',
            'https://nautil.us/category/microbiology/feed',
        ),
        (
            'PSYCHOLOGY',
            'https://nautil.us/category/psychology/feed',
        ),
        (
            'ECONOMICS',
            'https://nautil.us/category/economics/feed',
        ),
        (
            'GEOSCIENCE',
            'https://nautil.us/category/geoscience/feed',
        ),
        (
            'NEUROSCIENCE',
            'https://nautil.us/category/neuroscience/feed',
        ),
        (
            'SOCIOLOGY',
            'https://nautil.us/category/sociology/feed',
        ),
    ]
