From 203523a770c46c22813b788d80ac87c2ff80de84 Mon Sep 17 00:00:00 2001 From: oh45454545 Date: Mon, 22 Apr 2019 21:48:02 +0200 Subject: [PATCH 1/3] adapter_asianfanficscom fixes --- fanficfare/adapters/adapter_asianfanficscom.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fanficfare/adapters/adapter_asianfanficscom.py b/fanficfare/adapters/adapter_asianfanficscom.py index 9af8574b..aff88679 100644 --- a/fanficfare/adapters/adapter_asianfanficscom.py +++ b/fanficfare/adapters/adapter_asianfanficscom.py @@ -172,6 +172,7 @@ class AsianFanFicsComAdapter(BaseSiteAdapter): for index, chapter in enumerate(chapters): if chapter.text != 'Foreword': # skip the foreword self.add_chapter(chapter.text,'https://' + self.getSiteDomain() + chapter['value']) # note: AFF cuts off chapter names in list. this gets kind of fixed later on + # find timestamp a = soup.find('span', text='Updated') if a == None: @@ -190,7 +191,10 @@ class AsianFanFicsComAdapter(BaseSiteAdapter): self.story.setMetadata('status', 'In-Progress') # story description - a = soup.find('div', {'id':'story-description'}) + jsonlink = soup.find('link',href=re.compile(r'/api/forewords/[0-9]+/foreword_[0-9a-z]+.json')) + fore_json = json.loads(self._fetchUrl(jsonlink['href'])) + content = self.make_soup(fore_json['post']).find('body') # BS4 adds if not present. + a = content.find('div', {'id':'story-description'}) if a: self.setDescription(url,a) @@ -216,6 +220,12 @@ class AsianFanFicsComAdapter(BaseSiteAdapter): if a: a = a.parent.find('time') self.story.setMetadata('dateUpdated', makeDate(a['datetime'], self.dateformat)) + + # word count + a = soup.find('span', text='Total Word Count') + if a: + a = a.find_next('span') + self.story.setMetadata('numWords', int(a.text.split()[0])) # upvote, subs, and views a = soup.find('div',{'class':'title-meta'}) @@ -253,7 +263,6 @@ class AsianFanFicsComAdapter(BaseSiteAdapter): jsonlink = soup.find('link',href=re.compile(r'/api/chapters/[0-9]+/chapter_[0-9a-z]+.json')) chap_json = json.loads(self._fetchUrl(jsonlink['href'])) content = self.make_soup(chap_json['post']).find('body') # BS4 adds if not present. - content.name='div' # change body to a div. if self.getConfig('inject_chapter_title'): # the dumbest workaround ever for the abbreviated chapter titles from before logger.debug("Injecting full-length chapter title") From 8f260451bddfa10b392f32068bc2375bb8c3ebff Mon Sep 17 00:00:00 2001 From: oh45454545 Date: Mon, 22 Apr 2019 22:25:50 +0200 Subject: [PATCH 2/3] that line should be there --- fanficfare/adapters/adapter_asianfanficscom.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fanficfare/adapters/adapter_asianfanficscom.py b/fanficfare/adapters/adapter_asianfanficscom.py index aff88679..ac121ca0 100644 --- a/fanficfare/adapters/adapter_asianfanficscom.py +++ b/fanficfare/adapters/adapter_asianfanficscom.py @@ -263,6 +263,7 @@ class AsianFanFicsComAdapter(BaseSiteAdapter): jsonlink = soup.find('link',href=re.compile(r'/api/chapters/[0-9]+/chapter_[0-9a-z]+.json')) chap_json = json.loads(self._fetchUrl(jsonlink['href'])) content = self.make_soup(chap_json['post']).find('body') # BS4 adds if not present. + content.name='div' # change body to a div. if self.getConfig('inject_chapter_title'): # the dumbest workaround ever for the abbreviated chapter titles from before logger.debug("Injecting full-length chapter title") From ebf506a71ecb6d79a3df52840b27306748a466d3 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Mon, 22 Apr 2019 18:22:12 -0500 Subject: [PATCH 3/3] Remove a little extra whitespace. --- fanficfare/adapters/adapter_asianfanficscom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fanficfare/adapters/adapter_asianfanficscom.py b/fanficfare/adapters/adapter_asianfanficscom.py index ac121ca0..8532bc1a 100644 --- a/fanficfare/adapters/adapter_asianfanficscom.py +++ b/fanficfare/adapters/adapter_asianfanficscom.py @@ -220,7 +220,7 @@ class AsianFanFicsComAdapter(BaseSiteAdapter): if a: a = a.parent.find('time') self.story.setMetadata('dateUpdated', makeDate(a['datetime'], self.dateformat)) - + # word count a = soup.find('span', text='Total Word Count') if a: