__license__ = 'GPL v3'
__copyright__ = '2010, Darko Miletic <darko.miletic at gmail.com>'
'''
www.businessinsider.com
'''

from calibre.web.feeds.news import BasicNewsRecipe


class Business_insider(BasicNewsRecipe):
    title = 'Business Insider'
    __author__ = 'Darko Miletic'
    description = 'Noticias de Argentina y el resto del mundo'
    publisher = 'Business Insider, Inc.'
    category = 'news, politics, finances, world'
    oldest_article = 2
    max_articles_per_feed = 200
    no_stylesheets = True
    encoding = 'utf8'
    use_embedded_content = True
    language = 'en'
    remove_empty_feeds = True
    publication_type = 'newsportal'
    masthead_url = 'http://static.businessinsider.com/assets/images/logos/tbi_print.jpg'
    extra_css = '''
                               body{font-family: Arial,Helvetica,sans-serif }
                               img{margin-bottom: 0.4em; display:block}
                            '''

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

    remove_tags = [dict(name=['meta', 'link']), dict(attrs={'class': 'feedflare'})]
    remove_attributes = ['lang', 'border']

    feeds = [
        ('Latest', 'http://feeds2.feedburner.com/businessinsider'),
        ('Markets', 'http://feeds.feedburner.com/TheMoneyGame'),
        ('Wall Street', 'http://feeds.feedburner.com/clusterstock'),
        ('Tech', 'http://feeds.feedburner.com/typepad/alleyinsider/silicon_alley_insider'),
        ('The Wire', 'http://feeds.feedburner.com/businessinsider/thewire'),
        ('War Room', 'http://feeds.feedburner.com/businessinsider/warroom'),
        ('Sports', 'http://feeds.feedburner.com/businessinsider/sportspage'),
        ('Tools', 'http://feeds.feedburner.com/businessinsider/tools'),
        ('Travel', 'http://feeds.feedburner.com/businessinsider/travel'),
    ]

    def preprocess_html(self, soup):
        for item in soup.findAll(style=True):
            del item['style']
        for item in soup.findAll('a'):
            if item['href'].startswith('http://feedads'):
                item.extract()
            elif item.string is not None:
                tstr = item.string
                item.replaceWith(tstr)
        for item in soup.findAll('img', alt=False):
            item['alt'] = 'image'
        return soup
