#!/usr/bin/env python

__license__   = 'GPL v3'
__copyright__ = 'Copyright 2011 Starson17'
'''
engadget.com
'''

from calibre.web.feeds.news import BasicNewsRecipe


class Engadget(BasicNewsRecipe):
    title                 = u'Engadget'
    __author__            = 'Starson17, modified by epubli'
    __version__           = 'v2.0'
    __date__              = '14, Sep 2022'
    description           = 'Tech news'
    language              = 'en'
    oldest_article        = 7
    max_articles_per_feed = 100
    no_stylesheets        = True
    use_embedded_content  = False
    remove_javascript     = True
    remove_empty_feeds    = True
    compress_news_images = True
    scale_news_images_to_device = True
    cover_url = 'https://upload.wikimedia.org/wikipedia/commons/b/bb/Engadget-logo.svg'

    keep_only_tags = [ 
        dict(name='figure', attrs={'data-component':'DefaultLede'}),
        dict(name='div', attrs={'data-component':'ArticleHeader'}),
        dict(name='div', attrs={'class':['article-text','article-text c-gray-1 no-review']}),
        dict(name='figure')
    ]
    remove_tags = [
        dict(name='div', attrs={'data-component':'ArticleAuthorInfo'}),
        dict(name='div', attrs={'class':['notification-upsell-push display-push-promos_D(b) D(n) Bgc(#fff) Bdrs(4px) Bd(notificationBorder) Bxsh(notificationBoxShadow) Miw(410px) Maw(650px) Mb(20px)']}),
        dict(name='div', attrs={'class':['article-slideshow','D(f) Jc(c) Ai(c) W(100%) H(72px) H(120px)!--sm W(320px)!--sm Bgc(engadgetGhostWhite) C(engadgetFontBlack) Bdw(1px) Bdts(s) Bdc(#eaeaeb) Bds(s) Ov(h) Mt(20px) Pstart(10px)--md']}),
        dict(name='a', attrs={'class':'rapid-with-clickid athena-button'})
    ]

    feeds = [(u'Posts', u'https://www.engadget.com/rss.xml')]

    def parse_feeds(self):
      # Call parent's method.
      feeds = BasicNewsRecipe.parse_feeds(self)
      # Loop through all feeds.
      for feed in feeds:
        # Loop through all articles in feed.
        for article in feed.articles[:]:
          # Remove articles with '...' in the title.
          if 'best tech deals' in article.title:
              print('Removing:',article.title)
              feed.articles.remove(article)
          elif 'Podcast' in article.title:
              print('Removing:',article.title)
              feed.articles.remove(article)
          elif 'The Morning After' in article.title:
              print('Removing:',article.title)
              feed.articles.remove(article)
      return feeds


