mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
New recipe for The New England Journal of Medicine by Krittika Goyal
This commit is contained in:
parent
925b3ea1fc
commit
c5fa78d868
86
resources/recipes/nejm.recipe
Normal file
86
resources/recipes/nejm.recipe
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
import string, re
|
||||||
|
from calibre import strftime
|
||||||
|
from calibre.web.feeds.recipes import BasicNewsRecipe
|
||||||
|
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
||||||
|
|
||||||
|
class NYTimes(BasicNewsRecipe):
|
||||||
|
|
||||||
|
title = 'New England Journal of Medicine'
|
||||||
|
__author__ = 'Krittika Goyal'
|
||||||
|
description = 'Medical news'
|
||||||
|
timefmt = ' [%d %b, %Y]'
|
||||||
|
needs_subscription = True
|
||||||
|
|
||||||
|
no_stylesheets = True
|
||||||
|
#remove_tags_before = dict(name='h1', attrs={'class':'heading'})
|
||||||
|
#remove_tags_after = dict(name='td', attrs={'class':'newptool1'})
|
||||||
|
remove_tags = [
|
||||||
|
dict(name='iframe'),
|
||||||
|
#dict(name='div', attrs={'class':'related-articles'}),
|
||||||
|
#dict(name='div', attrs={'id':['qrformdiv', 'inSection', 'alpha-inner']}),
|
||||||
|
dict(name='form', attrs={'onsubmit':"return verifySearch(this.w,'Keyword, citation, or author')"}),
|
||||||
|
dict(name='table', attrs={'cellspacing':'0'}),
|
||||||
|
]
|
||||||
|
|
||||||
|
def preprocess_html(self, soup):
|
||||||
|
table = soup.find('table')
|
||||||
|
if table is not None:
|
||||||
|
table.extract()
|
||||||
|
return soup
|
||||||
|
|
||||||
|
#TO LOGIN
|
||||||
|
def get_browser(self):
|
||||||
|
br = BasicNewsRecipe.get_browser()
|
||||||
|
br.open('http://content.nejm.org/cgi/login?uri=/')
|
||||||
|
br.select_form(nr=0)
|
||||||
|
br['username'] = self.username
|
||||||
|
br['code'] = self.password
|
||||||
|
response = br.submit()
|
||||||
|
raw = response.read()
|
||||||
|
if '<strong>Welcome' 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):
|
||||||
|
soup = self.nejm_get_index()
|
||||||
|
|
||||||
|
div = soup.find(id='centerTOC')
|
||||||
|
|
||||||
|
current_section = None
|
||||||
|
current_articles = []
|
||||||
|
feeds = []
|
||||||
|
for x in div.findAll(True):
|
||||||
|
if x.name == 'img' and '/toc/' in x.get('src', '') and 'uarrow.gif' not in x.get('src', ''):
|
||||||
|
# Section heading found
|
||||||
|
if current_articles and current_section and 'Week in the' not in current_section:
|
||||||
|
feeds.append((current_section, current_articles))
|
||||||
|
current_section = x.get('alt')
|
||||||
|
current_articles = []
|
||||||
|
self.log('\tFound section:', current_section)
|
||||||
|
if current_section is not None and x.name == 'strong':
|
||||||
|
title = self.tag_to_string(x)
|
||||||
|
a = x.parent.find('a', href=lambda x: x and '/full/' in x)
|
||||||
|
if a is None:
|
||||||
|
continue
|
||||||
|
url = a.get('href', False)
|
||||||
|
if not url or not title:
|
||||||
|
continue
|
||||||
|
if url.startswith('/'):
|
||||||
|
url = 'http://content.nejm.org'+url
|
||||||
|
self.log('\t\tFound article:', title)
|
||||||
|
self.log('\t\t\t', url)
|
||||||
|
if url.startswith('/'):
|
||||||
|
url = 'http://online.wsj.com'+url
|
||||||
|
current_articles.append({'title': title, 'url':url,
|
||||||
|
'description':'', 'date':''})
|
||||||
|
|
||||||
|
if current_articles and current_section:
|
||||||
|
feeds.append((current_section, current_articles))
|
||||||
|
|
||||||
|
return feeds
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user