from calibre.web.feeds.news import BasicNewsRecipe


class APOD(BasicNewsRecipe):
    title = 'Astronomy Picture of the Day'
    __author__ = 'Starson17'
    description = 'Astronomy Pictures'
    language = 'en'
    use_embedded_content = False
    no_stylesheets = True
    cover_url = 'http://apod.nasa.gov/apod/image/1003/m78_torregrosa.jpg'
    remove_javascript = True
    recursions = 0
    oldest_article = 14
    remove_attributes = ['onmouseover', 'onmouseout']

    feeds = [('Astronomy Picture of the Day', 'http://apod.nasa.gov/apod.rss')]

    extra_css = '''
                    h1{font-family:Arial,Helvetica,sans-serif; font-weight:bold;font-size:large;}
                    h2{font-family:Arial,Helvetica,sans-serif; font-weight:normal;font-size:small;}
                    p{font-family:Arial,Helvetica,sans-serif;font-size:small;}
                    body{font-family:Helvetica,Arial,sans-serif;font-size:small;}
    '''

    def postprocess_html(self, soup, first_fetch):
        center_tags = soup.findAll(['center'])
        p_tags = soup.findAll(['p'])
        last_center = center_tags[-1:]
        last_center[0].extract()
        first_p = p_tags[:1]
        for tag in first_p:
            tag.extract()
        last2_p = p_tags[-2:]
        for tag in last2_p:
            tag.extract()
        return soup
