from calibre.web.feeds.news import BasicNewsRecipe
import re


class f1ultra(BasicNewsRecipe):
    title = u'Formuła 1 - F1 ultra'
    __license__ = 'GPL v3'
    __author__ = 'MrStefan <mrstefaan@gmail.com>, Artur Stachecki <artur.stachecki@gmail.com>'
    language = 'pl'
    description = u'Formuła 1, Robert Kubica, F3, GP2 oraz inne serie wyścigowe.'
    masthead_url = 'http://www.f1ultra.pl/templates/f1ultra/images/logo.gif'
    remove_empty_feeds = True
    oldest_article = 1
    max_articles_per_feed = 100
    remove_javascript = True
    no_stylesheets = True

    keep_only_tags = [(dict(name='div', attrs={'id': 'main'}))]
    remove_tags_after = [
        dict(attrs={'style': 'margin-top:5px;margin-bottom:5px;display: inline;'})]
    remove_tags = [
        (dict(attrs={'class': ['buttonheading', 'avPlayerContainer', 'createdate']}))]
    remove_tags.append(dict(attrs={'title': ['PDF', 'Drukuj', 'Email']}))
    remove_tags.append(dict(name='form', attrs={'method': 'post'}))
    remove_tags.append(dict(name='hr', attrs={'size': '2'}))

    preprocess_regexps = [(re.compile(r'align="left"'), lambda match: ''),
                          (re.compile(r'align="right"'), lambda match: ''),
                          (re.compile(r'width=\"*\"'), lambda match: ''),
                          (re.compile(r'\<table .*?\>'), lambda match: '')]

    extra_css = '''.contentheading { font-size: 1.4em; font-weight: bold; }
                   img { display: block; clear: both;}
                '''
    remove_attributes = ['width', 'height', 'position', 'float',
                         'padding-left', 'padding-right', 'padding', 'text-align']

    feeds = [
        (u'F1 Ultra', u'http://www.f1ultra.pl/index.php?option=com_rd_rss&id=1&Itemid=245')]
