Fix New England Journal of Medicine and Journal of Hospital Medicine

This commit is contained in:
Kovid Goyal 2010-12-18 18:23:33 -07:00
parent 281058618c
commit 2d9f56ffb9
2 changed files with 40 additions and 46 deletions

View File

@ -1,78 +1,72 @@
# -*- coding: utf-8 -*- import re
from calibre.web.feeds.recipes import BasicNewsRecipe from calibre.web.feeds.recipes import BasicNewsRecipe
class JournalofHospitalMedicine(BasicNewsRecipe): class JournalofHospitalMedicine(BasicNewsRecipe):
title = 'Journal of Hospital Medicine' title = 'Journal of Hospital Medicine'
__author__ = 'Krittika Goyal' __author__ = 'Kovid Goyal'
description = 'Medical news' description = 'Medical news'
timefmt = ' [%d %b, %Y]' timefmt = ' [%d %b, %Y]'
needs_subscription = True needs_subscription = True
language = 'en' language = 'en'
no_stylesheets = True no_stylesheets = True
keep_only_tags = [dict(id=['articleTitle', 'articleMeta', 'fulltext'])]
remove_tags = [dict(attrs={'class':'licensedContent'})]
# TO LOGIN # TO LOGIN
def get_browser(self): def get_browser(self):
br = BasicNewsRecipe.get_browser() br = BasicNewsRecipe.get_browser()
br.open('http://www3.interscience.wiley.com/cgi-bin/home') br.open('http://www3.interscience.wiley.com/cgi-bin/home')
br.select_form(name='siteLogin') br.select_form(nr=0)
br['LoginName'] = self.username br['j_username'] = self.username
br['Password'] = self.password br['j_password'] = self.password
response = br.submit() response = br.submit()
raw = response.read() raw = response.read()
if 'userName = ""' in raw: if '<h2>LOGGED IN</h2>' not in raw:
raise Exception('Login failed. Check your username and password') raise Exception('Login failed. Check your username and password')
return br return br
#TO GET ARTICLE TOC #TO GET ARTICLE TOC
def johm_get_index(self): def johm_get_index(self):
return self.index_to_soup('http://www3.interscience.wiley.com/journal/111081937/home') return self.index_to_soup('http://onlinelibrary.wiley.com/journal/10.1002/(ISSN)1553-5606/currentissue')
# To parse artice toc # To parse artice toc
def parse_index(self): def parse_index(self):
parse_soup = self.johm_get_index() soup = self.johm_get_index()
toc = soup.find(id='issueTocGroups')
div = parse_soup.find(id='contentCell')
current_section = None
current_articles = []
feeds = [] feeds = []
for x in div.findAll(True): for group in toc.findAll('li', id=re.compile(r'group\d+')):
if x.name == 'h4': gtitle = group.find(attrs={'class':'subSectionHeading'})
# Section heading found if gtitle is None:
if current_articles and current_section:
feeds.append((current_section, current_articles))
current_section = self.tag_to_string(x)
current_articles = []
self.log('\tFound section:', current_section)
if current_section is not None and x.name == 'strong':
title = self.tag_to_string(x)
p = x.parent.parent.find('a', href=lambda x: x and '/HTMLSTART' in x)
if p is None:
continue continue
url = p.get('href', False) gtitle = self.tag_to_string(gtitle)
if not url or not title: arts = group.find(attrs={'class':'articles'})
if arts is None:
continue continue
self.log('Found section:', gtitle)
articles = []
for art in arts.findAll(attrs={'class':lambda x: x and 'tocArticle'
in x}):
a = art.find('a', href=True)
if a is None:
continue
url = a.get('href')
if url.startswith('/'): if url.startswith('/'):
url = 'http://www3.interscience.wiley.com'+url url = 'http://onlinelibrary.wiley.com' + url
url = url.replace('/HTMLSTART', '/main.html,ftx_abs') url = url.replace('/abstract', '/full')
self.log('\t\tFound article:', title) title = self.tag_to_string(a)
self.log('\t\t\t', url) a.extract()
#if url.startswith('/'): pm = art.find(attrs={'class':'productMenu'})
#url = 'http://online.wsj.com'+url if pm is not None:
current_articles.append({'title': title, 'url':url, pm.extract()
'description':'', 'date':''}) desc = self.tag_to_string(art)
self.log('\tFound article:', title, 'at', url)
if current_articles and current_section: articles.append({'title':title, 'url':url, 'description':desc,
feeds.append((current_section, current_articles)) 'date':''})
if articles:
feeds.append((gtitle, articles))
return feeds return feeds
def preprocess_html(self, soup):
for img in soup.findAll('img', src=True):
img['src'] = img['src'].replace('tfig', 'nfig')
return soup

View File

@ -4,7 +4,7 @@ from calibre.web.feeds.recipes import BasicNewsRecipe
class NYTimes(BasicNewsRecipe): class NYTimes(BasicNewsRecipe):
title = 'New England Journal of Medicine' title = 'New England Journal of Medicine'
__author__ = 'Krittika Goyal' __author__ = 'Kovid Goyal'
description = 'Medical news' description = 'Medical news'
timefmt = ' [%d %b, %Y]' timefmt = ' [%d %b, %Y]'
needs_subscription = True needs_subscription = True