Update Prospect Magazine

This commit is contained in:
Kovid Goyal 2016-08-05 07:42:31 +05:30
parent a16d159724
commit e54f13b2f0

View File

@ -7,8 +7,8 @@ __license__ = 'GPL v3'
calibre recipe for prospectmagazine.co.uk (subscription) calibre recipe for prospectmagazine.co.uk (subscription)
''' '''
import re
from calibre.web.feeds.recipes import BasicNewsRecipe from calibre.web.feeds.recipes import BasicNewsRecipe
from css_selectors import Select
class ProspectMagUK(BasicNewsRecipe): class ProspectMagUK(BasicNewsRecipe):
@ -18,16 +18,13 @@ class ProspectMagUK(BasicNewsRecipe):
timefmt = ' [%d %B %Y]' timefmt = ' [%d %B %Y]'
no_stylesheets = True no_stylesheets = True
publication_type = 'magazine' publication_type = 'magazine'
masthead_url = 'http://www.prospectmagazine.co.uk/wp-content/themes/prospect/images/titleMain.jpg'
category = 'news, UK' category = 'news, UK'
language = 'en_GB' language = 'en_GB'
max_articles_per_feed = 100 max_articles_per_feed = 100
auto_cleanup = True
needs_subscription = True needs_subscription = True
auto_cleanup_keep = '//div[@class="lead_image"]'
INDEX = 'http://www.prospectmagazine.co.uk/issue/' INDEX = 'http://www.prospectmagazine.co.uk/issue/'
keep_only_tags = [dict(id='post_content')]
def get_browser(self): def get_browser(self):
br = BasicNewsRecipe.get_browser(self) br = BasicNewsRecipe.get_browser(self)
@ -40,41 +37,19 @@ class ProspectMagUK(BasicNewsRecipe):
return br return br
def parse_index(self): def parse_index(self):
soup = self.index_to_soup(self.INDEX) root = self.index_to_soup(self.INDEX, as_tree=True)
div = soup.find('div', id='cover_image') sel = Select(root)
if div is not None: for img in sel('.block_this_month .img_wrap img'):
img = div.find('img', src=True) self.cover_url = img.get('src').partition('?')[0]
if img is not None:
src = img['src']
if src.startswith('/'):
src = 'http://www.prospectmagazine.co.uk' + src
self.cover_url = src
feeds = [] feeds = []
# loop through sections for h2 in sel('h2.block-title'):
for sect in soup.findAll('div', attrs={'class': 'sectionheading'}): current_section = self.tag_to_string(h2)
fname = self.tag_to_string(sect).replace('>', '').strip()
self.log('Found section', fname)
articles = [] articles = []
self.log('Found section:', current_section)
# note: can't just find siblings with class='post' because that will also for div in sel('div.block_home_post', h2.getparent()):
# grab all the articles belonging to the sections that follow. for a in sel('div.title a[href]', div):
for item in sect.findNextSiblings('div', attrs={'class': True}): articles.append({'title':self.tag_to_string(a), 'url':a.get('href')})
if 'post' not in item['class']: self.log('\tFound article:', articles[-1]['title'])
break if articles:
a = item.find('a', href=True) feeds.append((current_section, articles))
if a is None:
continue
url = a['href']
title = self.tag_to_string(a)
p = item.find('p')
desc = self.tag_to_string(p) if p is not None else ''
art = {'title': title, 'description': desc,
'date': ' ', 'url': url}
p = item.find(attrs={'class': re.compile('author')})
self.log('\tFound article:', title, '::', url)
if p is not None:
art['author'] = self.tag_to_string(p).strip()
articles.append(art)
feeds.append((fname, articles))
return feeds return feeds