diff --git a/ffnet.py b/ffnet.py index 94fd995..f3e101f 100644 --- a/ffnet.py +++ b/ffnet.py @@ -117,17 +117,12 @@ class FFNet(FanfictionSiteAdapter): def getText(self, url): data = self._fetchUrl(url) - lines = data.split('\n') - - textbuf = '' - emit = False - olddata = data try: data = data.decode('utf8') except: data = olddata - + try: soup = bs.BeautifulStoneSoup(data) except: @@ -195,4 +190,4 @@ class FFA_UnitTests(unittest.TestCase): text = f.getText(url) self.assertTrue(text.find('Kale Resgerald at your service" He answered, "So, can we go now? Or do you want to') != -1) if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() diff --git a/output.py b/output.py index 4a5387c..8b412a9 100644 --- a/output.py +++ b/output.py @@ -136,7 +136,7 @@ class EPubFanficWriter(FanficWriter): self.storyTitle = removeEntities(name) self.name = makeAcceptableFilename(name) self.directory = self.basePath + '/' + self.name - self.authorName = removeEntities(author) + self.authorName = removeEntities(author+" aa") self.inmemory = inmemory @@ -195,14 +195,21 @@ class EPubFanficWriter(FanficWriter): if t.name in ('center'): t['class']=t.name t.name='div' - - allPs = self.soup.findAll(recursive=True) - for p in allPs: - if p.string != None and len(p.string.strip()) == 0 : - p.extract() + # removes paired, but empty tags. + if t.string != None and len(t.string.strip()) == 0 : + t.extract() text = self.soup.__str__('utf8') + # ffnet(& maybe others) gives the whole chapter text + # as one line. This causes problems for nook(at + # least) when the chapter size starts getting big + # (200k+) Using Soup's prettify() messes up italics + # and such. Done after soup extract so

and
+ # tags are normalized. Doing it here seems less evil + # than hacking BeautifulSoup, but it's debatable. + text = text.replace('

','

\n').replace('
','
\n') + self._writeFile(fn, XHTML_START % (title, title)) self._writeFile(fn, text) self._writeFile(fn, XHTML_END)