| 1 |
import re |
| 2 |
|
| 3 |
from calibre.web.feeds.recipes import BasicNewsRecipe |
| 4 |
|
| 5 |
|
| 6 |
class JournalofHospitalMedicine(BasicNewsRecipe): |
| 7 |
title = 'Journal of Hospital Medicine' |
| 8 |
__author__ = 'Kovid Goyal' |
| 9 |
description = 'Medical news' |
| 10 |
timefmt = ' [%d %b, %Y]' |
| 11 |
needs_subscription = True |
| 12 |
language = 'en' |
| 13 |
|
| 14 |
no_stylesheets = True |
| 15 |
keep_only_tags = [dict(id=['articleTitle', 'articleMeta', 'fulltext'])] |
| 16 |
remove_tags = [dict(attrs={'class': 'licensedContent'})] |
| 17 |
|
| 18 |
def get_browser(self): |
| 19 |
br = BasicNewsRecipe.get_browser(self) |
| 20 |
br.open('https://onlinelibrary.wiley.com/') |
| 21 |
br.select_form(nr=0) |
| 22 |
br['login'] = self.username |
| 23 |
br['password'] = self.password |
| 24 |
response = br.submit() |
| 25 |
raw = response.read() |
| 26 |
if '<h2>LOGGED IN</h2>' not in raw: |
| 27 |
raise Exception('Login failed. Check your username and password') |
| 28 |
return br |
| 29 |
|
| 30 |
# TO GET ARTICLE TOC |
| 31 |
def johm_get_index(self): |
| 32 |
return self.index_to_soup('https://shmpublications.onlinelibrary.wiley.com/toc/15535606/current') |
| 33 |
|
| 34 |
# To parse article toc |
| 35 |
def parse_index(self): |
| 36 |
soup = self.johm_get_index() |
| 37 |
toc = soup.find(id='issueTocGroups') |
| 38 |
feeds = [] |
| 39 |
for group in toc.findAll('li', id=re.compile(r'group\d+')): |
| 40 |
gtitle = group.find(attrs={'class': 'subSectionHeading'}) |
| 41 |
if gtitle is None: |
| 42 |
continue |
| 43 |
gtitle = self.tag_to_string(gtitle) |
| 44 |
arts = group.find(attrs={'class': 'articles'}) |
| 45 |
if arts is None: |
| 46 |
continue |
| 47 |
self.log('Found section:', gtitle) |
| 48 |
articles = [] |
| 49 |
for art in arts.findAll(attrs={'class': lambda x: x and 'tocArticle' in x}): |
| 50 |
a = art.find('a', href=True) |
| 51 |
if a is None: |
| 52 |
continue |
| 53 |
url = a.get('href') |
| 54 |
if url.startswith('/'): |
| 55 |
url = 'http://onlinelibrary.wiley.com' + url |
| 56 |
url = url.replace('/abstract', '/full') |
| 57 |
title = self.tag_to_string(a) |
| 58 |
a.extract() |
| 59 |
pm = art.find(attrs={'class': 'productMenu'}) |
| 60 |
if pm is not None: |
| 61 |
pm.extract() |
| 62 |
desc = self.tag_to_string(art) |
| 63 |
self.log('\tFound article:', title, 'at', url) |
| 64 |
articles.append({'title': title, 'url': url, 'description': desc, 'date': ''}) |
| 65 |
if articles: |
| 66 |
feeds.append((gtitle, articles)) |
| 67 |
|
| 68 |
return feeds |