__license__   = 'GPL v3'
__copyright__ = '2010, Darko Miletic <darko.miletic at gmail.com>'
'''
www.nursingtimes.net
'''

import urllib
from calibre.web.feeds.recipes import BasicNewsRecipe

class NursingTimes(BasicNewsRecipe):
    title                  = 'Nursing Times'
    __author__             = 'Darko Miletic'
    description            = 'Nursing practice, NHS and health care news'
    oldest_article         = 8
    max_articles_per_feed  = 100
    no_stylesheets         = True
    use_embedded_content   = False
    encoding               = 'utf-8'
    publisher              = 'emap'
    category               = 'news, health, nursing, UK'
    language               = 'en_GB'
    needs_subscription     = True
    LOGIN                  = 'http://www.nursingtimes.net/sign-in'

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

    def get_browser(self):
        br = BasicNewsRecipe.get_browser()
        br.open(self.LOGIN)
        if self.username is not None and self.password is not None:
            data = urllib.urlencode({ 'campaigncode' :'0'
                                     ,'referrer'     :''
                                     ,'security_text':''
                                     ,'SIemail'      :self.username
                                     ,'passWord'     :self.password
                                     ,'LoginButton.x':'27'
                                     ,'LoginButton.y':'13'
                                   })
            br.open(self.LOGIN,data)
        return br

    keep_only_tags   = [dict(name='div', attrs={'class':'storytext'})]
    remove_tags      = [
                          dict(name=['object','link','script','iframe'])
                         ,dict(name='div',attrs={'id':'comments_form'})
                       ]
    remove_tags_after = dict(name='div',attrs={'id':'comments_form'})

    feeds = [
               (u'Breaking News', u'http://www.nursingtimes.net/XmlServers/navsectionRSS.aspx?navsectioncode=1')
              ,(u'Practice', u'http://www.nursingtimes.net/XmlServers/navsectionRSS.aspx?navsectioncode=512')
              ,(u'Behind the headlines', u'http://www.nursingtimes.net/XmlServers/navsectionRSS.aspx?navsectioncode=468')
              ,(u'Analysis', u'http://www.nursingtimes.net/XmlServers/navsectionRSS.aspx?navsectioncode=62')
              ,(u'Acute care news', u'http://www.nursingtimes.net/XmlServers/navsectionRSS.aspx?navsectioncode=5')
              ,(u'Primary vare news', u'http://www.nursingtimes.net/XmlServers/navsectionRSS.aspx?navsectioncode=231')
              ,(u'Mental Health news', u'http://www.nursingtimes.net/XmlServers/navsectionRSS.aspx?navsectioncode=27')
              ,(u'Management news', u'http://www.nursingtimes.net/XmlServers/navsectionRSS.aspx?navsectioncode=32')
              ,(u"Older people's nursing news", u'http://www.nursingtimes.net/XmlServers/navsectionRSS.aspx?navsectioncode=181')
              ,(u'Respiratory news', u'http://www.nursingtimes.net/XmlServers/navsectionRSS.aspx?navsectioncode=177')
              ,(u'Wound care news', u'http://www.nursingtimes.net/XmlServers/navsectionRSS.aspx?navsectioncode=182')
            ]

