from calibre.web.feeds.recipes import BasicNewsRecipe


class iHeuteRecipe(BasicNewsRecipe):
    __author__ = 'FunThomas'
    title = u'iDnes.cz'
    publisher = u'MAFRA a.s.'
    description = 'iDNES.cz Zprávy, Technet, Komiksy a další'
    oldest_article = 3
    max_articles_per_feed = 2

    feeds = [
        (u'Zprávy', u'http://servis.idnes.cz/rss.asp?c=zpravodaj'),
        (u'Sport', u'http://servis.idnes.cz/rss.asp?c=sport'),
        (u'Technet', u'http://servis.idnes.cz/rss.asp?c=technet'),
        (u'Mobil', u'http://servis.idnes.cz/rss.asp?c=mobil'),
        (u'Ekonomika', u'http://servis.idnes.cz/rss.asp?c=ekonomikah'),
        (u'Cestování', u'http://servis.idnes.cz/rss.asp?c=iglobe'),
        (u'Komixy', u'http://servis.idnes.cz/rss.asp?c=komiksy')
    ]

    encoding = 'cp1250'
    language = 'cs'
    cover_url = 'http://g.idnes.cz/u/loga-n4/idnes.gif'
    remove_javascript = True
    no_stylesheets = True

    remove_attributes = ['width', 'height']
    remove_tags = [dict(name='div',   attrs={'id': ['zooming']}),
                   dict(name='div',   attrs={
                        'class': ['related', 'mapa-wrapper']}),
                   dict(name='table', attrs={'id': ['opener-img', 'portal']}),
                   dict(name='table', attrs={'class': ['video-16ku9']})]
    remove_tags_after = [
        dict(name='div', attrs={'id': ['related', 'related2']})]

    keep_only_tags = [dict(name='div', attrs={'class': [
                           'art-full adwords-text', 'dil-day', 'art-full']}), dict(name='table', attrs={'class': ['kemel-box']})]

    def print_version(self, url):
        print_url = url
        split_url = url.split("?")
        if (split_url[0].rfind('dilbert.asp') != -1):  # dilbert komix
            print_url = print_url.replace('.htm', '.gif&tisk=1')
            print_url = print_url.replace('.asp', '.aspx')
        elif (split_url[0].rfind('kemel.asp') == -1):  # not Kemel komix
            print_url = 'http://zpravy.idnes.cz/tiskni.asp?' + split_url[1]
        # kemel                  kemel print page doesn't work
        return print_url

    extra_css = '''
                  h1 {font-size:125%; font-weight:bold}
                  h3 {font-size:110%; font-weight:bold}
                '''
