#!/usr/bin/env  python

from calibre.web.feeds.news import BasicNewsRecipe, classes

class HindustanTimes(BasicNewsRecipe):
    title = u'Hindustan Times'
    description = 'News from India.'
    language = 'en_IN'
    __author__ = 'unkn0wn'
    oldest_article = 1  # days
    max_articles_per_feed = 50
    encoding = 'utf-8'
    use_embedded_content = False
    no_stylesheets = True
    remove_attributes = ['style', 'height', 'width']
    ignore_duplicate_articles = {'url'}

    keep_only_tags = [
            dict(name='h1'),
            dict(name='div', attrs={'class':'sortDec'}),
            dict(name='picture'),
            dict(name='figcaption'),
            dict(name='div', attrs={'class':['dateTime','storyBy','storyDetails','detail freemiumText','paywall']}),
            ]
    remove_tags = [
        dict(name='div', attrs={'class':['htsWrapper','shareArticle','new__newsletter__signup','signup__box subscribe','freemium-card','adMinHeight313','storyTopics','embed_div','shareIcons']}),
        dict(name='footer'),
        dict(name='a', attrs={'class':'closeStory close-btn'}),
    ]
        
    feeds = [
        ('India News','https://www.hindustantimes.com/feeds/rss/india-news/rssfeed.xml'),
        ('World News','https://www.hindustantimes.com/feeds/rss/world-news/rssfeed.xml'),
        ('HT Insight','https://www.hindustantimes.com/feeds/rss/ht-insight/rssfeed.xml'),
        ('editorial','https://www.hindustantimes.com/feeds/rss/editorials/rssfeed.xml'),
        ('Opinion','https://www.hindustantimes.com/feeds/rss/opinion/rssfeed.xml'),
        ('Business','https://www.hindustantimes.com/feeds/rss/business/rssfeed.xml'),
        ('Elections','https://www.hindustantimes.com/feeds/rss/elections/rssfeed.xml'),
        ('Science','https://www.hindustantimes.com/feeds/rss/science/rssfeed.xml'),
        ('Sports','https://www.hindustantimes.com/feeds/rss/sports/rssfeed.xml'),
        ('Education','https://www.hindustantimes.com/feeds/rss/education/rssfeed.xml'),
        ('Books','https://www.hindustantimes.com/feeds/rss/books/rssfeed.xml'),
        ('HT Weekend','https://www.hindustantimes.com/feeds/rss/ht-weekend/rssfeed.xml'),
        #('Entertainment','https://www.hindustantimes.com/feeds/rss/entertainment/rssfeed.xml'),
        ]
    def preprocess_html(self, soup):
        for img in soup.findAll('img', attrs={'data-src': True}):
            img['src'] = img['data-src']
        return soup


calibre_most_common_ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36'