#!/usr/bin/env python
__license__ = 'GPL v3'
__author__ = 'Lorenzo Vigentini'
__copyright__ = '2009, Lorenzo Vigentini <l.vigentini at gmail.com>'
__version__ = 'v1.01'
__date__ = '14, January 2010'
__description__ = 'PC World and Macworld consistently deliver editorial excellence through award-winning content and trusted product reviews.'

'''
http://www.pcworld.com/
'''

from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ptempfile import PersistentTemporaryFile

temp_files = []
articles_are_obfuscated = True


class pcWorld(BasicNewsRecipe):
    __author__ = 'Lorenzo Vigentini'
    description = 'PC World and Macworld consistently deliver editorial excellence through award-winning content and trusted product reviews.'
    cover_url = 'http://images.pcworld.com/images/common/header/header-logo.gif'

    title = 'PCWorld '
    publisher = 'IDG Communication'
    category = 'PC, video, computing, product reviews, editing, cameras, production'

    language = 'en'
    timefmt = '[%a, %d %b, %Y]'

    oldest_article = 7
    max_articles_per_feed = 20
    use_embedded_content = False
    recursion = 10

    remove_javascript = True
    no_stylesheets = True
    auto_cleanup = True

    def get_obfuscated_article(self, url):
        br = self.get_browser()
        br.open(url + '&print')

        response = br.follow_link(url, nr=0)
        html = response.read()

        self.temp_files.append(PersistentTemporaryFile('_fa.html'))
        self.temp_files[-1].write(html)
        self.temp_files[-1].close()
        return self.temp_files[-1].name

    feeds = [
        (u'All Stories', u'http://www.pcworld.com/index.rss'),
        (u'Reviews', u'http://www.pcworld.com/reviews/index.rss'),
        (u'How-To', u'http://www.pcworld.com/howto/index.rss'),
        (u'Video', u'http://www.pcworld.com/video/index.rss'),
        (u'Game On', u'http://www.pcworld.com/column/game-on/index.rss'),
        (u'Hassle free PC', u'http://www.pcworld.com/column/hassle-free-pc/index.rss'),
        (u'Go Social', u'http://www.pcworld.com/column/go-social/index.rss'),
        (u'Linux Line', u'http://www.pcworld.com/column/linux-line/index.rss'),
        (u'Net Work', u'http://www.pcworld.com/column/net-work/index.rss'),
        (u'Security Alert', u'http://www.pcworld.com/column/security-alert/index.rss'),
        (u'Simply Business', u'http://www.pcworld.com/column/simply-business/index.rss'),
        (u'Business', u'http://www.pcworld.com/category/business/index.rss'),
        (u'Security & Privacy', u'http://www.pcworld.com/category/privacy/index.rss'),
        (u'Windows', u'http://www.pcworld.com/category/windows/index.rss'),
        (u'Laptops', u'http://www.pcworld.com/category/laptop-computers/index.rss'),
        (u'Software', u'http://www.pcworld.com/category/software/index.rss'),
        (u'Desktops', u'http://www.pcworld.com/category/desktop-computers/index.rss'),
        (u'Printers', u'http://www.pcworld.com/category/printers/index.rss'),
        (u'Phones', u'http://www.pcworld.com/category/phones/index.rss'),
        (u'Tablets', u'http://www.pcworld.com/category/tablets/index.rss')
    ]

