#!/usr/bin/env  python2

__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
'''
usatoday.com
'''

from calibre.web.feeds.news import BasicNewsRecipe


class USAToday(BasicNewsRecipe):

    title = 'USA Today'
    __author__ = 'Kovid Goyal'
    description = 'newspaper'
    encoding = 'utf-8'
    publisher = 'usatoday.com'
    category = 'news, usa'
    language = 'en'

    use_embedded_content = False
    timefmt = ' [%d %b %Y]'
    max_articles_per_feed = 15
    no_stylesheets = True
    remove_empty_feeds = True
    filterDuplicates = True

    extra_css = '''
                    h1, h2 {
                        font-size:xx-large;
                        font-family:Arial,Helvetica,sans-serif;}
                    #post-attributes, .info,
                    .clear {
                        font-size:xx-small; color:#4D4D4D;
                        font-family:Arial,Helvetica,sans-serif;
                    }
                    #post-body,
                    #content {
                        font-size:medium;
                        font-family:Arial,Helvetica,sans-serif;
                    }
                '''

    feeds = [
        ('Top Headlines',
         'http://rssfeeds.usatoday.com/usatoday-NewsTopStories'),
        ('Tech Headlines',
         'http://rssfeeds.usatoday.com/usatoday-TechTopStories'),
        ('Personal Tech',
         'http://rssfeeds.usatoday.com/UsatodaycomTech-PersonalTalk'),
        ('Health',
         'http://rssfeeds.usatoday.com/UsatodaycomHealth-TopStories'),
        ('Travel Headlines',
         'http://rssfeeds.usatoday.com/UsatodaycomTravel-TopStories'),
        ('Money Headlines',
         'http://rssfeeds.usatoday.com/UsatodaycomMoney-TopStories'),
        ('Entertainment Headlines',
         'http://rssfeeds.usatoday.com/usatoday-LifeTopStories'),
        ('Sport Headlines',
         'http://rssfeeds.usatoday.com/UsatodaycomSports-TopStories'),
        ('Weather Headlines',
         'http://rssfeeds.usatoday.com/usatoday-WeatherTopStories'),
        ('Most Popular',
         'http://rssfeeds.usatoday.com/Usatoday-MostViewedArticles'),
    ]

    auto_cleanup = True

    def get_masthead_url(self):
        masthead = 'http://i.usatoday.net/mobile/_common/_images/565x73_usat_mobile.gif'
        br = BasicNewsRecipe.get_browser(self)
        try:
            br.open(masthead)
        except:
            self.log("\nCover unavailable")
            masthead = None
        return masthead
