diff --git a/recipes/harpers_full.recipe b/recipes/harpers_full.recipe index b965bca9b8..153f82db7b 100644 --- a/recipes/harpers_full.recipe +++ b/recipes/harpers_full.recipe @@ -8,7 +8,7 @@ If you have institutional subscription based on access IP you do not need to ent anything in username/password fields ''' -import time +import time, re import urllib from calibre import strftime from calibre.web.feeds.news import BasicNewsRecipe @@ -29,7 +29,6 @@ class Harpers_full(BasicNewsRecipe): needs_subscription = 'optional' masthead_url = 'http://harpers.org/wp-content/themes/harpers/images/pheader.gif' publication_type = 'magazine' - INDEX = strftime('http://harpers.org/archive/%Y/%m') LOGIN = 'http://harpers.org/wp-content/themes/harpers/ajax_login.php' extra_css = """ body{font-family: adobe-caslon-pro,serif} @@ -65,17 +64,28 @@ class Harpers_full(BasicNewsRecipe): return br def parse_index(self): + #find current issue + soup = self.index_to_soup('http://harpers.org/') + currentIssue=soup.find('div',attrs={'class':'mainNavi'}).find('li',attrs={'class':'curentIssue'}) + currentIssue_url=self.tag_to_string(currentIssue.a['href']) + self.log(currentIssue_url) + + #go to the current issue + soup1 = self.index_to_soup(currentIssue_url) + date = re.split('\s\|\s',self.tag_to_string(soup1.head.title.string))[0] + self.timefmt = u' [%s]'%date + + #get cover + coverurl='http://harpers.org/wp-content/themes/harpers/ajax_microfiche.php?img=harpers-'+re.split('harpers.org/',currentIssue_url)[1]+'gif/0001.gif' + soup2 = self.index_to_soup(coverurl) + self.cover_url = self.tag_to_string(soup2.find('img')['src']) + self.log(self.cover_url) articles = [] - print 'Processing ' + self.INDEX - soup = self.index_to_soup(self.INDEX) count = 0 - for item in soup.findAll('div', attrs={'class':'articleData'}): + for item in soup1.findAll('div', attrs={'class':'articleData'}): text_links = item.findAll('h2') for text_link in text_links: if count == 0: - lcover_url = item.find(attrs={'class':'dwpdf'}) - if lcover_url: - self.cover_url = lcover_url.a['href'] count = 1 else: url = text_link.a['href'] @@ -87,7 +97,14 @@ class Harpers_full(BasicNewsRecipe): ,'url' :url ,'description':'' }) - return [(soup.head.title.string, articles)] + return [(soup1.head.title.string, articles)] def print_version(self, url): return url + '?single=1' + + def cleanup(self): + soup = self.index_to_soup('http://harpers.org/') + signouturl=self.tag_to_string(soup.find('li', attrs={'class':'subLogOut'}).findNext('li').a['href']) + self.log(signouturl) + self.browser.open(signouturl) +