from calibre.web.feeds.recipes import BasicNewsRecipe


class AdvancedUserRecipe1303841067(BasicNewsRecipe):
    title = 'Golem.de'
    __author__ = 'schuster'

    oldest_article = 7
    max_articles_per_feed = 10
    no_stylesheets = True
    use_embedded_content = False
    language = 'de'
    cover_url = 'http://www.e-energy.de/images/logo_golem.jpg'
    masthead_url = 'http://www.golem.de/staticrl/images/logo.png'
    extra_css = '''
                    h2{font-family:Arial,Helvetica,sans-serif; font-size: x-small;}
                    h1{ font-family:Arial,Helvetica,sans-serif;  font-size:x-large; font-weight:bold;}

                '''
    remove_javascript = True
    remove_tags_befor = [dict(name='header', attrs={'class': 'cluster-header'})]
    remove_tags_after = [dict(name='p', attrs={'class': 'meta'})]
    remove_tags = [
        dict(rel='nofollow'),
        dict(name='header', attrs={'id': 'header'}),
        dict(name='div', attrs={'class': 'dh1'}),
        dict(name='label', attrs={'class': 'implied'}),
        dict(name='section', attrs={'id': 'comments'}),
        dict(name='li', attrs={'class': 'gg_prebackcounterItem'}),
        dict(name='li', attrs={'class': 'gg_prebackcounterItem gg_embeddedIndexCounter'}),
        dict(name='img', attrs={'class': 'gg_embeddedIconRight gg_embeddedIconFS gg_cursorpointer'}),
        dict(name='div', attrs={'target': '_blank'}),
    ]

    def get_browser(self, *args, **kwargs):
        from calibre import browser

        kwargs['user_agent'] = 'mozilla'
        return browser(*args, **kwargs)

    def get_article_url(self, article):
        return article.get('id', article.get('guid', None))

    def preprocess_html(self, soup):
        for alink in soup.findAll('a'):
            if alink.string is not None:
                tstr = alink.string
                alink.replaceWith(tstr)
        return soup

    feeds = [
        ('Audio/Video', 'http://rss.golem.de/rss.php?tp=av&feed=RSS2.0'),
        ('Foto', 'http://rss.golem.de/rss.php?tp=foto&feed=RSS2.0'),
        ('Games', 'http://rss.golem.de/rss.php?tp=games&feed=RSS2.0'),
        ('Handy', 'http://rss.golem.de/rss.php?tp=handy&feed=RSS2.0'),
        ('Internet', 'http://rss.golem.de/rss.php?tp=inet&feed=RSS2.0'),
        ('Mobile', 'http://rss.golem.de/rss.php?tp=mc&feed=RSS2.0'),
        ('OSS', 'http://rss.golem.de/rss.php?tp=oss&feed=RSS2.0'),
        ('Politik/Recht', 'http://rss.golem.de/rss.php?tp=pol&feed=RSS2.0'),
        ('Security', 'http://rss.golem.de/rss.php?tp=sec&feed=RSS2.0'),
        ('Desktop-Applikationen', 'http://rss.golem.de/rss.php?tp=apps&feed=RSS2.0'),
        ('Software-Entwicklung', 'http://rss.golem.de/rss.php?tp=dev&feed=RSS2.0'),
        ('Wirtschaft', 'http://rss.golem.de/rss.php?tp=wirtschaft&feed=RSS2.0'),
        ('Hardware', 'http://rss.golem.de/rss.php?r=hw&feed=RSS2.0'),
        ('Software', 'http://rss.golem.de/rss.php?r=sw&feed=RSS2.0'),
        ('Networld', 'http://rss.golem.de/rss.php?r=nw&feed=RSS2.0'),
        ('Entertainment', 'http://rss.golem.de/rss.php?r=et&feed=RSS2.0'),
        ('TK', 'http://rss.golem.de/rss.php?r=tk&feed=RSS2.0'),
        ('Wirtschaft', 'http://rss.golem.de/rss.php?r=wi&feed=RSS2.0'),
        ('E-Commerce', 'http://rss.golem.de/rss.php?r=ec&feed=RSS2.0'),
    ]
