#!/usr/bin/env python
# vim:fileencoding=utf-8
from __future__ import absolute_import, division, print_function, unicode_literals

from calibre.web.feeds.news import BasicNewsRecipe

# author:  <lionel.plais@ilp-web.net>


class LePeupleBreton(BasicNewsRecipe):
    title = 'Le Peuple Breton'
    __author__ = 'Lionel Plais'
    description = "Aujourd'hui, être libre c'est être informé"
    oldest_article = 90
    language = 'fr'
    cover_img_url = 'http://lepeuplebreton.bzh/wp-content/uploads/2017/11/le-peuple-breton-logo.jpg'
    masthead_url = cover_img_url
    remove_javascript = True
    no_stylesheets = True

    keep_only_tags = [
        dict(name='article'),
    ]

    remove_tags = [
        dict(name='div', attrs={'class': ['share-post', 'juiz_sps_links', 'counters_both', 'juiz_sps_displayed_bottom']}),
    ]

    feeds = [
        ('À la Une', 'http://lepeuplebreton.bzh/category/a-la-une/feed/'),
        ('Bretagne', 'http://lepeuplebreton.bzh/category/themes/bretagne/feed/'),
        ('France', 'http://lepeuplebreton.bzh/category/lieu/france/feed/'),
        ('International', 'http://lepeuplebreton.bzh/category/lieu/international-fr/feed/'),
        ('Point de vue', 'http://lepeuplebreton.bzh/category/themes/point-de-vue/feed/'),
        ('Économie', 'https://lepeuplebreton.bzh/category/themes/economie/feed/'),
        ('Écologie', 'http://lepeuplebreton.bzh/category/themes/ecologie/feed/'),
        ('Santé', 'http://lepeuplebreton.bzh/category/themes/sante/feed/'),
        ('Culture & Sport', 'http://lepeuplebreton.bzh/category/themes/culture/feed/'),
    ]

    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
