from calibre.web.feeds.news import BasicNewsRecipe


class EclipseOnline(BasicNewsRecipe):

    #
    # oldest_article specifies the maximum age, in days, of posts to retrieve.
    # The default of 32 is intended to work well with a "days of month = 1"
    # recipe schedule to download "monthly issues" of Eclipse Online.
    # Increase this value to include additional posts. However, the RSS feed
    # currently only includes the 10 most recent posts, so that's the max.
    #
    oldest_article = 32

    title = u'Eclipse Online'
    description = u'"Where strange and wonderful things happen, where reality is eclipsed for a little while with something magical and new." Eclipse Online is edited by Jonathan Strahan and published online by Night Shade Books. http://www.nightshadebooks.com/category/eclipse/'  # noqa
    publication_type = 'magazine'
    language = 'en'

    __author__ = u'Jim DeVona'
    __version__ = '1.0'

    # For now, use this Eclipse Online logo as the ebook cover image.
    # (Disable the cover_url line to let Calibre generate a default cover, including date.)
    cover_url = 'http://www.nightshadebooks.com/wp-content/uploads/2012/10/Eclipse-Logo.jpg'

    # Extract the "post" div containing the story (minus redundant metadata)
    # from each page.
    keep_only_tags = [
        dict(name='div', attrs={'class': lambda x: x and 'post' in x})]
    remove_tags = [
        dict(name='span', attrs={'class': ['post-author', 'post-category', 'small']})]

    # Nice plain markup (like Eclipse's) works best for most e-readers.
    # Disregard any special styling rules, but center illustrations.
    auto_cleanup = False
    no_stylesheets = True
    remove_attributes = ['style', 'align']
    extra_css = '.wp-caption {text-align: center;} .wp-caption-text {font-size: small; font-style: italic;}'

    # Tell Calibre where to look for article links. It will proceed to retrieve
    # these posts and format them into an ebook according to the above rules.
    feeds = ['http://www.nightshadebooks.com/category/eclipse/feed/']
