Read New England Journal of Medicine on your iPad or Kindle in no time. Click download to load the free ebook on your reader.

Check out all the available public recipes or write your own with these quick start guides. ReadBeam is built on calibre, so everything in the docs and the fora applies here as well.

Download for free »

Print issue - paid content. The New England Journal of Medicine (NEJM) is an English-language peer-reviewed medical journal published by the Massachusetts Medical Society.

Language: en

Requires Subscription: Yes, requires a New England Journal of Medicine subscription

Schedule Every morning

			  # -*- coding: utf-8 -*-
from calibre.web.feeds.recipes import BasicNewsRecipe

class NYTimes(BasicNewsRecipe):

    title       = 'New England Journal of Medicine'
    __author__  = 'Kovid Goyal'
    description = 'Medical news'
    timefmt = ' [%d %b, %Y]'
    needs_subscription = True
    language = 'en'

    no_stylesheets = True
    keep_only_tags = dict(id='content')


    #TO LOGIN
    def get_browser(self):
        br = BasicNewsRecipe.get_browser()
        br.open('http://www.nejm.org/action/showLogin?uri=http://www.nejm.org/')
        br.select_form(name='frmLogin')
        br['login'] = self.username
        br['password'] = self.password
        response = br.submit()
        raw = response.read()
        if '>Sign Out<' not in raw:
            raise Exception('Login failed. Check your username and password')
        return br

    #TO GET ARTICLE TOC
    def nejm_get_index(self):
        return self.index_to_soup('http://content.nejm.org/current.dtl')

    # To parse artice toc
    def parse_index(self):
        parse_soup = self.nejm_get_index()

        feeds = []

        div = parse_soup.find(attrs={'class':'tocContent'})
        for group in div.findAll(attrs={'class':'articleGrouping'}):
            feed_title = group.find(attrs={'class':'articleType'})
            if feed_title is None:
                continue
            feed_title = self.tag_to_string(feed_title)
            articles = []
            self.log('Found section:', feed_title)
            for art in group.findAll(attrs={'class':lambda x: x and 'articleEntry'
                in x}):
                link = art.find(attrs={'class':lambda x:x and 'articleLink' in
                    x})
                if link is None:
                    continue
                a = link.find('a', href=True)
                if a is None:
                    continue
                url = a.get('href')
                if url.startswith('/'):
                    url = 'http://www.nejm.org'+url
                title = self.tag_to_string(a)
                self.log.info('\tFound article:', title, 'at', url)
                article = {'title':title, 'url':url, 'date':''}
                au = art.find(attrs={'class':'articleAuthors'})
                if au is not None:
                    article['author'] = self.tag_to_string(au)
                desc = art.find(attrs={'class':'hover_text'})
                if desc is not None:
                    desc = self.tag_to_string(desc)
                    if 'author' in article:
                        desc = ' by ' + article['author'] + ' ' +desc
                    article['description'] = desc
                articles.append(article)
            if articles:
                feeds.append((feed_title, articles))

        return feeds