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

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

from datetime import date

from calibre.web.feeds.news import BasicNewsRecipe


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: E501
    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 = [
        ('Politika', 'https://www.danas.rs/rubrika/politika/feed/'),
        ('Drustvo', 'https://www.danas.rs/rubrika/drustvo/feed/'),
        ('Dijalog', 'https://www.danas.rs/rubrika/dijalog/feed/'),
        ('Ekonomija', 'https://www.danas.rs/rubrika/ekonomija/feed/'),
        ('Svet', 'https://www.danas.rs/rubrika/svet/feed/'),
        ('Sport', 'https://www.danas.rs/rubrika/sport/feed/'),
        ('Kultura', 'https://www.danas.rs/rubrika/kultura/feed/'),
        ('Scena', 'https://www.danas.rs/rubrika/scena/feed/'),
        ('Zivot', 'https://www.danas.rs/rubrika/zivot/feed/'),
        ('Auto', 'https://www.danas.rs/rubrika/auto/feed/'),
        ('IT', 'https://www.danas.rs/rubrika/tehnologije/feed/'),
        ('Ljudi', 'https://www.danas.rs/rubrika/ljudi/feed/'),
        ('Beograd', 'https://www.danas.rs/rubrika/beograd/feed/'),
        ('Famozno', '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
