from calibre.web.feeds.news import BasicNewsRecipe

class Adventure_zone(BasicNewsRecipe):
    title          = u'Adventure Zone'
    __author__        = 'fenuks'
    description   = 'Adventure zone - adventure games from A to Z'
    category       = 'games'
    language       = 'pl'
    oldest_article = 15
    max_articles_per_feed = 100
    no_stylesheets = True
    remove_tags_before= dict(name='td', attrs={'class':'main-bg'})
    remove_tags_after= dict(name='td', attrs={'class':'main-body middle-border'})
    extra_css              = '.main-bg{text-align: left;}  td.capmain{ font-size: 22px; }'
    feeds          = [(u'Nowinki', u'http://www.adventure-zone.info/fusion/feeds/news.php')]

    def get_cover_url(self):
        soup = self.index_to_soup('http://www.adventure-zone.info/fusion/news.php')
        cover=soup.find(id='box_OstatninumerAZ')
        self.cover_url='http://www.adventure-zone.info/fusion/'+ cover.center.a.img['src']
        return getattr(self, 'cover_url', self.cover_url)


    def skip_ad_pages(self, soup):
        skip_tag = soup.body.findAll(name='a')
        if skip_tag is not None:
            for r in skip_tag:
                 if 'articles.php?' in r['href']:
                     if r.strong is not None:
                         word=r.strong.string
                         if ('zapowied' or 'recenzj') in word:
                             return self.index_to_soup('http://www.adventure-zone.info/fusion/print.php?type=A&item_id'+r['href'][r['href'].find('_id')+3:], raw=True)
        else:
            None

    def print_version(self, url):
        return url.replace('news.php?readmore', 'print.php?type=N&item_id')

