from calibre.web.feeds.news import BasicNewsRecipe

class Archeowiesci(BasicNewsRecipe):
    title          = u'Archeowieści'
    __author__        = 'fenuks'
    category       = 'archeology'
    language       = 'pl'
    description = u'Z pasją o przeszłości'
    cover_url='http://archeowiesci.pl/wp-content/uploads/2011/05/Archeowiesci2-115x115.jpg'
    oldest_article = 7
    needs_subscription='optional'
    max_articles_per_feed = 100
    auto_cleanup = True
    remove_tags=[dict(name='span', attrs={'class':['post-ratings', 'post-ratings-loading']})]
    feeds          = [(u'Archeowieści', u'http://archeowiesci.pl/feed/')]

    def parse_feeds (self):
      feeds = BasicNewsRecipe.parse_feeds(self)
      for feed in feeds:
        for article in feed.articles[:]:
          if self.username is None and 'subskrypcja' in article.title:
            feed.articles.remove(article)
      return feeds

    def get_browser(self):
        br = BasicNewsRecipe.get_browser(self)
        if self.username is not None and self.password is not None:
            br.open('http://archeowiesci.pl/wp-login.php')
            br.select_form(name='loginform')
            br['log']   = self.username
            br['pwd'] = self.password
            br.submit()
        return br
