mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-09-29 15:31:08 -04:00
Fixes #1464886 [Unable to fetch news from the entrepeneur magazine](https://bugs.launchpad.net/calibre/+bug/1464886)
74 lines
2.5 KiB
Python
74 lines
2.5 KiB
Python
#!/usr/bin/env python2
|
|
# vim:fileencoding=utf-8
|
|
from __future__ import (unicode_literals, division, absolute_import,
|
|
print_function)
|
|
|
|
__license__ = 'GPL v3'
|
|
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
|
|
|
from calibre.web.feeds.news import BasicNewsRecipe
|
|
|
|
class EntrepeneurMagRecipe(BasicNewsRecipe):
|
|
__author__ = 'Kovid Goyal'
|
|
language = 'en'
|
|
|
|
title = u'Entrepeneur Magazine'
|
|
publisher = u'Entrepreneur Media, Inc'
|
|
category = u'Business'
|
|
description = u'Online magazine on business, small business, management and economy'
|
|
|
|
encoding = 'utf-8'
|
|
|
|
no_stylesheets = True
|
|
remove_javascript = True
|
|
|
|
keep_only_tags = [
|
|
dict(attrs={'class':['headline']}),
|
|
dict(itemprop='articlebody'),
|
|
]
|
|
remove_tags = [
|
|
dict(attrs={'class':['related-content']}),
|
|
]
|
|
remove_attributes = ['style']
|
|
|
|
INDEX = 'http://www.entrepreneur.com'
|
|
|
|
def parse_index(self):
|
|
root = self.index_to_soup(self.INDEX + '/magazine/index.html', as_tree=True)
|
|
for href in root.xpath('//div[@class="Ddeck title"]/a/@href'):
|
|
return self.parse_ent_index(self.INDEX + href)
|
|
|
|
def parse_ent_index(self, url):
|
|
root = self.index_to_soup(url, as_tree=True)
|
|
img = root.xpath('//div[@class="magcoverissue"]/img')[0]
|
|
self.cover_url = img.get('src')
|
|
self.timefmt = ' [%s]' % img.get('alt').rpartition('-')[-1].strip()
|
|
body = root.xpath('//div[@class="cbody"]')[0]
|
|
current_section = 'Unknown'
|
|
current_articles = []
|
|
ans = []
|
|
for x in body.xpath('descendant::*[name() = "h2" or name() = "h3"]'):
|
|
if x.tag == 'h2':
|
|
if current_articles:
|
|
ans.append((current_section, current_articles))
|
|
current_section = self.tag_to_string(x)
|
|
current_articles = []
|
|
self.log('Found section:', current_section)
|
|
else:
|
|
title = self.tag_to_string(x)
|
|
try:
|
|
a = x.xpath('./a')[0]
|
|
except IndexError:
|
|
continue
|
|
url = self.INDEX + a.get('href')
|
|
d = x.getnext()
|
|
desc = self.tag_to_string(d) if d is not None else ''
|
|
self.log('\t', title, 'at:', url)
|
|
self.log('\t\t', desc)
|
|
current_articles.append({'title':title, 'url':url, 'description':desc})
|
|
|
|
if current_articles:
|
|
ans.append((current_section, current_articles))
|
|
|
|
return ans
|