from calibre.web.feeds.news import BasicNewsRecipe


class AdvancedUserRecipe1282101454(BasicNewsRecipe):
    title = 'How To Geek'
    language = 'en'
    __author__ = 'TonytheBookworm, PatStapleton (update 2020-05-20)'
    description = 'Daily Computer Tips and Tricks'
    publisher = 'Howtogeek'
    category = 'PC,tips,tricks'
    oldest_article = 2
    max_articles_per_feed = 100
    linearize_tables = True
    no_stylesheets = True
    remove_javascript = True
    use_embedded_content = False

    keep_only_tags = [
        dict(id='main')
    ]
    remove_tags_after = dict(classes='affiliate-disclosure')
    remove_tags = [
        dict(name='a', attrs={'target': ['_blank']}),
        dict(name='table', attrs={'id': ['articleTable']}),
        dict(name='div',   attrs={'class': ['feedflare', 'article-share-widgets', 'related-articles', 'comments', 'nextup']}),
    ]

    feeds = [
        ('How-to Geek', 'https://www.howtogeek.com/feed/')

    ]

    def preprocess_html(self, soup, *a):
        for img in soup.findAll('img', attrs={'data-pagespeed-lazy-src': True}):
            img['src'] = img['data-pagespeed-lazy-src']
        return soup
