From 87adf8f4e2990770c99dd278b884676467b98406 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Tue, 23 Apr 2019 19:35:17 -0500 Subject: [PATCH] Require login for adapter_asianfanficscom, except when already logged in. Tweak not-sub'ed msg too. --- .../adapters/adapter_asianfanficscom.py | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/fanficfare/adapters/adapter_asianfanficscom.py b/fanficfare/adapters/adapter_asianfanficscom.py index c5cb19eb..83c1cfce 100644 --- a/fanficfare/adapters/adapter_asianfanficscom.py +++ b/fanficfare/adapters/adapter_asianfanficscom.py @@ -85,14 +85,12 @@ class AsianFanFicsComAdapter(BaseSiteAdapter): data = self._postUrl(loginUrl, params) soup = self.make_soup(data) - - loginCheck = soup.find('div',{'id':'login'}) - if loginCheck: + if self.loginNeededCheck(soup): logger.info('Failed to login to URL %s as %s' % (loginUrl, params['username'])) raise exceptions.FailedToLogin(url,params['username']) - return False - else: - return True + + def loginNeededCheck(self,soup): + return soup.find('div',{'id':'login'}) != None def doStorySubscribe(self, url, soup): subHref = soup.find('a',{'id':'subscribe'}) @@ -133,12 +131,12 @@ class AsianFanFicsComAdapter(BaseSiteAdapter): # use BeautifulSoup HTML parser to make everything easier to find. soup = self.make_soup(data) - # require login to avoid lots of headaches - self.performLogin(url,soup) - - # refresh website after logging in - data = self._fetchUrl(url,usecache=False) - soup = self.make_soup(data) + if self.loginNeededCheck(soup): + # always login if not already to avoid lots of headaches + self.performLogin(url,soup) + # refresh website after logging in + data = self._fetchUrl(url,usecache=False) + soup = self.make_soup(data) # subscription check subCheck = soup.find('div',{'class':'click-to-read-full'}) @@ -149,7 +147,7 @@ class AsianFanFicsComAdapter(BaseSiteAdapter): else: raise exceptions.FailedToDownload("Error when subscribing to story. This usually means a change in the website code.") elif subCheck and not self.getConfig("auto_sub"): - raise exceptions.FailedToDownload("This story is marked as subscribers-only. In order to download such stories, auto_sub must be set to true in personal.ini, as this website removes certain HTML tags and portions of the text otherwise.") + raise exceptions.FailedToDownload("This story is only available to subscribers. You can subscribe manually on the web site, or set auto_sub:true in personal.ini.") ## Title a = soup.find('h1', {'id': 'story-title'})