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

'''
www.alo.rs
'''

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


class Alo_Novine(BasicNewsRecipe):
    title = 'Alo!'
    __author__ = 'Darko Miletic'
    description = "News Portal from Serbia"
    publisher = 'Alo novine d.o.o.'
    category = 'news, politics, Serbia'
    oldest_article = 2
    max_articles_per_feed = 100
    delay = 4
    no_stylesheets = True
    encoding = 'utf-8'
    use_embedded_content = False
    language = 'sr'
    extra_css             = """
                                @font-face {font-family: "sans1";src:url(res:///opt/sony/ebook/FONT/tt0003m_.ttf)}
                                .article_description,body{font-family: Arial,Helvetica,sans1,sans-serif}
                                .lead {font-size: 1.3em}
                                h1{color: #DB0700}
                                .article_uvod{font-style: italic; font-size: 1.2em}
                                img{margin-bottom: 0.8em} """

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

    preprocess_regexps = [(re.compile(u'\u0110'), lambda match: u'\u00D0')]

    remove_tags = [dict(name=['object', 'link', 'embed'])]
    remove_attributes = ['height', 'width']

    feeds = [

    (u'Najnovije Vijesti', u'http://www.alo.rs/rss/danasnje_vesti'),
    (u'Politika', u'http://www.alo.rs/rss/politika'),
    (u'Vesti', u'http://www.alo.rs/rss/vesti'),
    (u'Sport', u'http://www.alo.rs/rss/sport'),
    (u'Ljudi', u'http://www.alo.rs/rss/ljudi'),
    (u'Saveti', u'http://www.alo.rs/rss/saveti')
    ]

    def preprocess_html(self, soup):
        for item in soup.findAll(style=True):
            del item['style']
        return soup

    def print_version(self, url):
        artl = url.rpartition('/')[0]
        artid = artl.rpartition('/')[2]
        return 'http://www.alo.rs/resources/templates/tools/print.php?id=' + artid

    def image_url_processor(self, baseurl, url):
        return url.replace('alo.rs//', 'alo.rs/')
