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