#!/usr/bin/env python

__license__ = 'GPL v3'
__copyright__ = '2008-2011, Lionel Bergeret <lbergeret at gmail.com>'
'''
dhnet.be
'''

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


class DHNetBe(BasicNewsRecipe):
    title = 'La Derniere Heure'
    __author__ = 'Lionel Bergeret'
    description = 'News from Belgium in French'
    publisher = 'dhnet.be'
    category = 'news, Belgium'
    oldest_article = 3
    language = 'fr'
    masthead_url = 'http://www.dhnet.be/images/homepage_logo_dh.gif'

    max_articles_per_feed = 20
    no_stylesheets = True
    use_embedded_content = False
    timefmt = ' [%d %b %Y]'

    keep_only_tags = [dict(name='div', attrs={'id': 'articleText'}), dict(name='div', attrs={'id': 'articlePicureAndLinks'})]

    feeds = [('La Une', 'http://www.dhnet.be/rss'), ('La Une Sports', 'http://www.dhnet.be/rss/dhsports/'), ('La Une Info', 'http://www.dhnet.be/rss/dhinfos/')]

    def preprocess_html(self, soup):
        for alink in soup.findAll('a'):
            if alink.string is not None:
                tstr = alink.string
                alink.replaceWith(tstr)
        return soup

    def get_cover_url(self):
        cover_url = strftime('http://pdf-online.dhnet.be/pdfonline/image/%Y%m%d/dh_%Y%m%d_nam_infoge_001.pdf.L.jpg')
        return cover_url
