#!/usr/bin/env  python
# -*- coding: utf-8 -*-

__license__     = 'GPL v3'
__copyright__   = '04 December 2010, desUBIKado'
__author__      = 'desUBIKado'
__description__ = 'Daily newspaper from Aragon'
__version__     = 'v0.09'
__date__        = '07, August 2013'
'''
elperiodicodearagon.com
'''
from calibre.web.feeds.news import BasicNewsRecipe


class elperiodicodearagon(BasicNewsRecipe):
    title                 = u'El Periodico de Aragon'
    __author__            = u'desUBIKado'
    description           = u'Noticias desde Aragon'
    publisher             = u'elperiodicodearagon.com'
    category              = u'news, politics, Spain, Aragon'
    oldest_article        = 1
    delay                 = 0
    max_articles_per_feed = 100
    no_stylesheets        = True
    use_embedded_content  = False
    language              = 'es'
    masthead_url          = 'http://pdf.elperiodicodearagon.com/img/logotipo.gif'
    encoding              = 'iso-8859-1'
    remove_empty_feeds    = True
    remove_javascript     = True

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

    feeds              = [
                           (u'Portada', u'http://zetaestaticos.com/aragon/rss/portada_es.xml'),
                           (u'Arag\xf3n', u'http://zetaestaticos.com/aragon/rss/2_es.xml'),
                           (u'Internacional', u'http://zetaestaticos.com/aragon/rss/4_es.xml'),
                           (u'Espa\xf1a', u'http://zetaestaticos.com/aragon/rss/3_es.xml'),
                           (u'Econom\xeda', u'http://zetaestaticos.com/aragon/rss/5_es.xml'),
                           (u'Deportes', u'http://zetaestaticos.com/aragon/rss/7_es.xml'),
                           (u'Real Zaragoza', u'http://zetaestaticos.com/aragon/rss/10_es.xml'),
                           (u'CAI Zaragoza', u'http://zetaestaticos.com/aragon/rss/91_es.xml'),
                           (u'Monta\xf1ismo', u'http://zetaestaticos.com/aragon/rss/354_es.xml'),
                           (u'Opini\xf3n', u'http://zetaestaticos.com/aragon/rss/103_es.xml'),
                           (u'Tema del d\xeda', u'http://zetaestaticos.com/aragon/rss/102_es.xml'),
                           (u'Escenarios', u'http://zetaestaticos.com/aragon/rss/105_es.xml'),
                           (u'Sociedad', u'http://zetaestaticos.com/aragon/rss/104_es.xml'),
                           (u'Gente', u'http://zetaestaticos.com/aragon/rss/330_es.xml'),
                           (u'Espacio 3', u'http://zetaestaticos.com/aragon/rss/328_es.xml'),
                           (u'Fiestas del Pilar', u'http://zetaestaticos.com/aragon/rss/107_es.xml')
                         ]

    remove_attributes = ['height','width']

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

    # Recuperamos la portada de papel (la imagen format=1 tiene mayor resolucion)
    def get_cover_url(self):
        index = 'http://pdf.elperiodicodearagon.com/edicion.php'
        soup = self.index_to_soup(index)
        for image in soup.findAll('img',src=True):
            if image['src'].startswith('/funciones/img-public.php?key='):
                return 'http://pdf.elperiodicodearagon.com' + image['src']
        return None

    # Usamos la versión para móviles

    def print_version(self, url):
        return url.replace('http://www.elperiodicodearagon.com/', 'http://www.elperiodicodearagon.com/m/')

