__license__ = 'GPL v3'
__copyright__ = '2010, Darko Miletic <darko.miletic at gmail.com>'
'''
thewest.com.au
'''

import re
from calibre.web.feeds.news import BasicNewsRecipe


class TheWest(BasicNewsRecipe):
    title = 'The West Australian'
    __author__ = 'Darko Miletic'
    description = 'News from Australia'
    publisher = 'thewest.com.au'
    category = 'news, politics, Australia'
    oldest_article = 2
    max_articles_per_feed = 200
    no_stylesheets = True
    encoding = 'utf8'
    use_embedded_content = False
    language = 'en_AU'
    remove_empty_feeds = True
    publication_type = 'newspaper'
    masthead_url = 'http://l.yimg.com/ao/i/mp/properties/news/02/wan/img/wan-logo-h49.png'
    extra_css = ' .article{font-family: Arial,Helvetica,sans-serif } .image{font-size: x-small} '

    preprocess_regexps = [
        (re.compile(r'</title>.*?</head>', re.DOTALL |
                    re.IGNORECASE), lambda match: '</title></head>')
    ]

    conversion_options = {
        'comment': description, 'tags': category, 'publisher': publisher, 'language': language
    }

    remove_tags = [
        dict(attrs={'class': ['tools', 'lhs']}), dict(attrs={
            'id': 'tools-bottom'}), dict(attrs={'href': 'http://twitter.com/thewest_com_au'})
    ]
    keep_only_tags = [dict(attrs={'class': 'mod article'})]
    remove_attributes = ['width', 'height']

    feeds = [

    (u'WA News', u'http://d.yimg.com/au.rss.news.yahoo.com/thewest/wa.xml'),
    (u'National', u'http://d.yimg.com/au.rss.news.yahoo.com/thewest/national.xml'),
    (u'World', u'http://d.yimg.com/au.rss.news.yahoo.com/thewest/world.xml'),
    (u'Offbeat', u'http://d.yimg.com/au.rss.news.yahoo.com/thewest/offbeat.xml'),
    (u'Business', u'http://d.yimg.com/au.rss.news.yahoo.com/thewest/business.xml'),
    (u'Sport', u'http://d.yimg.com/au.rss.news.yahoo.com/thewest/sport.xml'),
    (u'Entertainment', u'http://d.yimg.com/au.rss.news.yahoo.com/thewest/entertainment.xml'),
    (u'Travel', u'http://d.yimg.com/au.rss.news.yahoo.com/thewest/travel.xml'),
    (u'Life+Style', u'http://d.yimg.com/au.rss.news.yahoo.com/thewest/lifestyle.xml')
    ]

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

    def preprocess_html(self, soup):
        return self.adeify_images(soup)
