#!/usr/pkg/bin/python3.13

__license__ = 'GPL v3'
__copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
'''
climateprogress.org
'''

from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import Tag


def new_tag(soup, name, attrs=()):
    impl = getattr(soup, 'new_tag', None)
    if impl is not None:
        return impl(name, attrs=dict(attrs))
    return Tag(soup, name, attrs=attrs or None)


class ClimateProgress(BasicNewsRecipe):
    title = 'Climate Progress'
    __author__ = 'Darko Miletic'
    description = "An insider's view of climate science, politics and solutions"
    publisher = 'Climate Progress'
    category = 'news, ecology, climate, blog'
    oldest_article = 7
    max_articles_per_feed = 100
    no_stylesheets = True
    use_embedded_content = True
    encoding = 'utf-8'
    language = 'en'

    lang = 'en-US'
    direction = 'ltr'

    html2lrf_options = [
        '--comment', description, '--category', category, '--publisher', publisher
    ]

    html2epub_options = 'publisher="' + publisher + \
        '"\ncomments="' + description + '"\ntags="' + category + '"'

    extra_css = '''
                h2{color:#003366;font-size: large ;font-family:Arial,Helvetica,sans-serif; font-weight:bold;}
                h3{color:#003366;font-size: small ;font-family:Arial,Helvetica,sans-serif; font-weight:bold;}
                h4{color:#003366;font-size: x-small ;font-family:Arial,Helvetica,sans-serif; font-weight:bold;}
                .date{color:#333333; font-size:xx-small; font-family:Arial,Helvetica,sans-serif; font-style:italic}
                a{color:#339966;}
                body{font-family:Georgia,Times New Roman,Times,serif; font-size:x-small;color:#333333;}
                '''

    feeds = [(u'Posts', u'http://feeds.feedburner.com/climateprogress/lCrX')]

    def preprocess_html(self, soup):
        soup.html['lang'] = self.lang
        soup.html['dir'] = self.direction
        mlang = new_tag(soup, 'meta', [
                    ("http-equiv", "Content-Language"), ("content", self.lang)])
        mcharset = new_tag(soup, 'meta', [
                       ("http-equiv", "Content-Type"), ("content", "text/html; charset=utf-8")])
        soup.head.insert(0, mlang)
        soup.head.insert(1, mcharset)
        return self.adeify_images(soup)
