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

__license__ = 'GPL v3'
__copyright__ = '2011 - 2016, Darko Miletic <darko.miletic at gmail.com>'
'''
www.frontline.in
'''

from calibre.web.feeds.news import BasicNewsRecipe


class Frontlineonnet(BasicNewsRecipe):
    title                = 'Frontline'
    __author__           = 'Darko Miletic'
    description          = """
India's National Magazine
Frontline, the fortnightly English magazine from the stable of The Hindu, has been a distinguished presence in the media world for the past 27 years.
As per the Indian Readership Survey (IRS) Q4, its average issue readership is 152,000.

Frontline's journalism is characterised by in-depth, insightful reporting and analysis of issues and events at the regional, national and international levels.
It excels in long-form journalism.

The topics Frontline covers range from politics, economics and social issues to the environment, nature, culture and cinema.
Its cover stories are comprehensive.
    """
    publisher            = 'Frontline'
    category             = 'news, politics, India'
    no_stylesheets       = True
    oldest_article       = 15
    INDEX                = 'http://www.frontline.in/'
    use_embedded_content = False
    encoding             = 'utf-8'
    language             = 'en_IN'
    publication_type     = 'magazine'
    auto_cleanup         = True
    masthead_url         = 'http://www.frontline.in/template/1-0-1/gfx/fl_logo.jpg'
    extra_css            = """
                              body{font-family: Georgia,"Times New Roman",serif}
                              img{margin-top:0.5em; margin-bottom: 0.7em; display: block}
                           """

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

    feeds = [
      (u'Cover story'       , u'http://www.frontline.in/cover-story/?service=rss'),
      (u'The Nation'        , u'http://www.frontline.in/the-nation/?service=rss'),
      (u'Politics'          , u'http://www.frontline.in/politics/?service=rss'),
      (u'Columns'           , u'http://www.frontline.in/columns/?service=rss'),
      (u'Social Issues'     , u'http://www.frontline.in/social-issues/?service=rss'),
      (u'General issues'    , u'http://www.frontline.in/social-issues/general-issues/?service=rss'),
      (u'Social justice'    , u'http://www.frontline.in/social-issues/social-justice/?service=rss'),
      (u'Arts&Culture'      , u'http://www.frontline.in/arts-and-culture/?service=rss'),
      (u'Economy'           , u'http://www.frontline.in/economy/?service=rss'),
      (u'World Affairs'     , u'http://www.frontline.in/world-affairs/?service=rss'),
      (u'Science&Technology', u'http://www.frontline.in/science-and-technology/?service=rss'),
      (u'Books'             , u'http://www.frontline.in/books/?service=rss'),
      (u'Sport'             , u'http://www.frontline.in/other/sport/?service=rss')
    ]

    def get_cover_url(self):
        soup = self.index_to_soup(self.INDEX)
        divtag = soup.find('div', 'smallMagCont')
        if divtag:
            return divtag.img['src']
        return None

    def print_version(self, url):
        return url.replace('?','?css=print&')
