__license__   = 'GPL v3'
__copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
'''
http://www.dilbert.com
DrMerry added cover Image 2011-11-12
'''

from calibre.web.feeds.recipes import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import BeautifulSoup
import re

class DilbertBig(BasicNewsRecipe):
    title                  = 'Dilbert'
    __author__             = 'Darko Miletic and Starson17 contribution of DrMerry'
    description            = 'Dilbert'
    reverse_article_order = True
    oldest_article         = 15
    max_articles_per_feed  = 100
    no_stylesheets         = True
    use_embedded_content   = False
    encoding               = 'utf-8'
    publisher              = 'UNITED FEATURE SYNDICATE, INC.'
    category               = 'comic'
    language               = 'en'
    cover_url         = 'http://dilbert.com/mobile/mobile/dilbert.app.icon.png'

    conversion_options = {
                             'comments'        : description
                            ,'tags'            : category
                            ,'language'        : language
                            ,'publisher'       : publisher
                         }

    feeds = [(u'Dilbert', u'http://feed.dilbert.com/dilbert/daily_strip')]

    preprocess_regexps = [
        (re.compile('strip\..*\.gif', re.DOTALL|re.IGNORECASE), lambda match: 'strip.zoom.gif')
        ]

    def preprocess_html(self, soup):
        for tag in soup.findAll(name='input'):
            image = BeautifulSoup('<img src=' + tag['value'] + '></img>')
        return image

