# -*- mode: python -*-
# -*- coding: utf-8 -*-

__license__ = 'GPL v3'
__copyright__ = '2008-2018, Darko Miletic <darko.miletic at gmail.com>'
'''
danas.rs
'''

from calibre.web.feeds.news import BasicNewsRecipe
from datetime import date


class Danas(BasicNewsRecipe):
    title = 'Danas'
    __author__ = 'Darko Miletic'
    description = 'Dnevne novine sa vestima iz sveta, politike, ekonomije, kulture, sporta, Beograda, Novog Sada i cele Srbije.'
    publisher = 'DAN GRAF d.o.o.'
    category = 'danas Dnevne novine politika drustvo ekonomija svet sport beograd vojvodina periskop terazije Beograd Srbija Novi Sad Nis Kragujevac Vojvodina politics Serbia'  # noqa
    oldest_article = 2
    max_articles_per_feed = 100
    no_stylesheets = False
    use_embedded_content = False
    encoding = 'utf-8'
    masthead_url = 'https://www.danas.rs/wp-content/themes/danas/assets/public/images/danas-logo.png'
    language = 'sr'
    remove_javascript = True
    publication_type = 'newspaper'
    remove_empty_feeds = True
    auto_cleanup = True
    auto_cleanup_keep = '//div[@class="post-intro-above"] //h1[@class="post-title"] | //div[@class="post-intro-title"] | //div[@class="post-meta-wrapper"]'
    resolve_internal_links = True
    extra_css = """
                                .author{font-size: small}
                                .published {font-size: small}
                                img{margin-bottom: 0.8em}
                            """

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

    feeds = [
        (u'Politika', u'https://www.danas.rs/rubrika/politika/feed/'),
        (u'Drustvo', u'https://www.danas.rs/rubrika/drustvo/feed/'),
        (u'Dijalog', u'https://www.danas.rs/rubrika/dijalog/feed/'),
        (u'Ekonomija', u'https://www.danas.rs/rubrika/ekonomija/feed/'),
        (u'Svet', u'https://www.danas.rs/rubrika/svet/feed/'),
        (u'Sport', u'https://www.danas.rs/rubrika/sport/feed/'),
        (u'Kultura', u'https://www.danas.rs/rubrika/kultura/feed/'),
        (u'Scena', u'https://www.danas.rs/rubrika/scena/feed/'),
        (u'Zivot', u'https://www.danas.rs/rubrika/zivot/feed/'),
        (u'Auto', u'https://www.danas.rs/rubrika/auto/feed/'),
        (u'IT', u'https://www.danas.rs/rubrika/tehnologije/feed/'),
        (u'Ljudi', u'https://www.danas.rs/rubrika/ljudi/feed/'),
        (u'Beograd', u'https://www.danas.rs/rubrika/beograd/feed/'),
        (u'Famozno', u'https://www.danas.rs/kolumnista/svetislav-basara/feed/'),
    ]

    def get_cover_url(self):
        months = ['januar', 'februar', 'mart', 'april', 'maj', 'jun', 'jul',
                  'avgust', 'septembar', 'oktobar', 'novembar', 'decembar']
        td = date.today()
        monthname = months[td.month - 1]
        lurl = td.strftime("https://www.danas.rs/naslovna/naslovna-strana-za-%d-" + monthname + "-%Y/")
        soup = self.index_to_soup(lurl)
        al = soup.find('div', attrs={'class':'corax-image'})
        if al and al.img:
            return al.img['src']
        return None
