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


class WiredITA(BasicNewsRecipe):
    title = u'Wired.it'
    oldest_article = 1
    max_articles_per_feed = 50
    no_stylesheets = True
    use_embedded_content = False
    auto_cleanup = False
    encoding = 'utf8'
    masthead_url = 'http://www.wired.com/images/home/wired_logo.gif'
    description = 'Wired - Make in Italy. Inventa, sbaglia, innova'
    publisher = 'http://www.wired.it/'
    language = 'it'
    __author__ = 'isspro'
    publication_type = 'magazine'

    conversion_options = {'title': title,
                          'comments': description,
                          'language': language,
                          'publisher': publisher,
                          'authors': title,
                          'smarten_punctuation': True
                          }

    keep_only_tags = [
        dict(name='div', attrs={'id': 'main-article'})
    ]

    remove_tags = [
        dict(name='img', attrs={'class': 'avatar img-circle'}),
        dict(name='div', attrs={'class': 'topics'}),
        dict(name='div', attrs={'class': 'social-share hidden-lg'}),
        dict(name='span', attrs={'class': 'label'})
    ]

    extra_css = '''
        h1 {font-size:x-large;}
        p.lead {font-size:medium;}
        .who {line-height: 0pt; margin: 0pt;}
    '''

    preprocess_regexps = [
        (re.compile(r'Pubblicato'), lambda match: '')

    ]

    feeds = [(u'Attualit\xe0', u'http://www.wired.it/attualita/feed/'),
             (u'Internet', 'http://www.wired.it/internet/feed/'),
             (u'Gadget', 'http://www.wired.it/gadget/feed/'),
             (u'Mobile', 'http://www.wired.it/mobile/feed/'),
             (u'Scienza', 'http://www.wired.it/scienza/feed/'),
             (u'Economia', 'http://www.wired.it/economia/feed/'),
             (u'LifeStyle', 'http://www.wired.it/lifestyle/feed/'),
             (u'Play', 'http://www.wired.it/play/feed/'),

             ]
