Fix Harvard Business Review

This commit is contained in:
Kovid Goyal 2013-01-30 10:59:00 +05:30
parent 6ace77f1bc
commit 5d3ec0672f

View File

@ -11,11 +11,11 @@ class HBR(BasicNewsRecipe):
timefmt = ' [%B %Y]'
language = 'en'
no_stylesheets = True
recipe_disabled = ('hbr.org has started requiring the use of javascript'
' to log into their website. This is unsupported in calibre, so'
' this recipe has been disabled. If you would like to see '
' HBR supported in calibre, contact hbr.org and ask them'
' to provide a javascript free login method.')
# recipe_disabled = ('hbr.org has started requiring the use of javascript'
# ' to log into their website. This is unsupported in calibre, so'
# ' this recipe has been disabled. If you would like to see '
# ' HBR supported in calibre, contact hbr.org and ask them'
# ' to provide a javascript free login method.')
LOGIN_URL = 'https://hbr.org/login?request_url=/'
LOGOUT_URL = 'https://hbr.org/logout?request_url=/'
@ -50,21 +50,25 @@ class HBR(BasicNewsRecipe):
f = br.select_form('#signin-form')
f['signin-form:username'] = 'test-account'
f['signin-form:password'] = 'testaccount'
br.submit(ajax_replies=3)
f.submit_control().qwe.evaluateJavaScript('this.click()')
br.run_for_a_time(30)
def map_url(self, url):
if url.endswith('/ar/1'):
return url[:-1]+'pr'
def hbr_get_toc(self):
#return self.index_to_soup(open('/t/hbr.html').read())
# return self.index_to_soup(open('/t/toc.html').read())
today = date.today()
future = today + timedelta(days=30)
for x in [x.strftime('%y%m') for x in (future, today)]:
url = self.INDEX + x
soup = self.index_to_soup(url)
if not soup.find(text='Issue Not Found'):
if (not soup.find(text='Issue Not Found') and not soup.find(
text="We're Sorry. There was an error processing your request")
and 'Exception: java.io.FileNotFoundException' not in
unicode(soup)):
return soup
raise Exception('Could not find current issue')
@ -72,8 +76,9 @@ class HBR(BasicNewsRecipe):
feeds = []
current_section = None
articles = []
for x in soup.find(id='archiveToc').findAll(['h3', 'h4']):
if x.name == 'h3':
for x in soup.find(id='issueFeaturesContent').findAll(['li', 'h4']):
if x.name == 'h4':
if x.get('class', None) == 'basic':continue
if current_section is not None and articles:
feeds.append((current_section, articles))
current_section = self.tag_to_string(x).capitalize()
@ -89,7 +94,7 @@ class HBR(BasicNewsRecipe):
if url.startswith('/'):
url = 'http://hbr.org' + url
url = self.map_url(url)
p = x.parent.find('p')
p = x.find('p', attrs={'class':'author'})
desc = ''
if p is not None:
desc = self.tag_to_string(p)
@ -101,7 +106,6 @@ class HBR(BasicNewsRecipe):
'date':''})
return feeds
def parse_index(self):
soup = self.hbr_get_toc()
# open('/t/hbr.html', 'wb').write(unicode(soup).encode('utf-8'))