# -*- coding: utf-8 -*-
from calibre.web.feeds import Feed
from calibre.web.feeds.news import BasicNewsRecipe


class GC_gl(BasicNewsRecipe):
    title = 'Galicia Confidencial (RSS)'
    __author__ = 'Susana Sotelo Docío'
    description = 'Unha fiestra de información aberta a todos'
    publisher = 'Galicia Confidencial'
    category = 'news, society, politics, Galicia'
    encoding = 'utf-8'
    language = 'gl'
    direction = 'ltr'
    cover_url = 'http://galiciaconfidencial.com/imagenes/header/logo_gc.gif'
    oldest_article = 5
    max_articles_per_feed = 100
    center_navbar = False

    feeds = [('Novas no RSS', 'http://galiciaconfidencial.com/rss2/xeral.rss')]

    extra_css = ' p{text-align:left} '

    def print_version(self, url):
        return url.replace('http://galiciaconfidencial.com/nova/', 'http://galiciaconfidencial.com/imprimir/')

    def parse_index(self):
        feeds = []
        self.gc_parse_feeds(feeds)
        return feeds

    def gc_parse_feeds(self, feeds):
        rssFeeds = Feed()
        rssFeeds = BasicNewsRecipe.parse_feeds(self)
        self.feed_to_index_append(rssFeeds[:], feeds)

    def feed_to_index_append(self, feedObject, masterFeed):
        for feed in feedObject:
            newArticles = []
            for article in feed.articles:
                newArt = {'title': article.title, 'url': article.url, 'date': article.date}
                newArticles.append(newArt)
            masterFeed.append((feed.title, newArticles))
