From 7f8d7a7dbb8b3f47f3578fd2883baa4a3b89da78 Mon Sep 17 00:00:00 2001
From: retiefjimm
Date: Mon, 11 Oct 2010 14:05:57 -0500
Subject: [PATCH] Add '\n' after each
and
tag. Extremely
long(200k+) single line chapters (like ffnet gives) causes problems for nook.
Also removed a little dead code from ffnet.py.
---
ffnet.py | 9 ++-------
output.py | 19 +++++++++++++------
2 files changed, 15 insertions(+), 13 deletions(-)
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)