Changed the title page generation to allow for easily adding and removing entries from the table of information shown.

Modified ffnet.py to use the mangled story title if given instead of the name portion of the URL.  As part of this, the Name and chapter number are now optional in the URL passed in.
This commit is contained in:
wsuetholz 2010-11-10 11:18:48 -06:00
parent 33d1fabd11
commit b2ea9c3e73
8 changed files with 70 additions and 22 deletions

View file

@ -29,6 +29,9 @@ class FanfictionSiteAdapter:
def setPassword(self, password):
pass
def getHost(self):
pass
def getStoryURL(self):
pass

View file

@ -27,20 +27,16 @@ h7 { text-align: left; font-size: large; font-weight: bold; }
MIMETYPE = '''application/epub+zip'''
TITLE_PAGE = '''<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
TITLE_HEADER = '''<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>%s - %s</title><link href="stylesheet.css" type="text/css" charset="UTF-8" rel="stylesheet"/></head><body>
<p><h7 id="lnks"><b><a id="StoryLink" href="%s">%s</a></b> by <b><a id="AuthorLink" href="%s">%s</a></b></h7></p>
<table class="full">
<tr><td><b>Category:</b></td><td>%s</td></tr>
<tr><td><b>Genre:</b></td><td>%s</td></tr>
<tr><td><b>Status:</b></td><td>%s</td></tr>
<tr><td><b>Published:</b></td><td>%s</td></tr>
<tr><td><b>Updated:</b></td><td>%s</td></tr>
<tr><td><b>Packaged:</b></td><td>%s</td></tr>
<tr><td><b>Rating Age/User:</b></td><td>%s / %s</td></tr>
<tr><td><b>Chapters/Words:</b></td><td>%s / %s</td></tr>
</table>
<p><b>URL:</b><pre id="url0"><br /><a id="StoryURL" href="%s">%s</a></pre></p>
'''
TITLE_ENTRY = '''<tr><td><b>%s</b></td><td>%s</td></tr>
'''
TITLE_FOOTER = '''</table>
<p><b>Summary:</b><br />%s</p>
</body></html>
'''

View file

@ -68,21 +68,29 @@ class FFNet(FanfictionSiteAdapter):
logging.debug('self.path=%s' % self.path)
spl = self.path.split('/')
logging.debug('spl=%s' % spl)
if len(spl) == 5:
self.path = "/".join(spl[1:-1])
self.outputName = spl[4] + '-ffnet_' + spl[2]
if self.path.startswith('/'):
self.path = self.path[1:]
spl = self.path.split('/')
logging.debug('spl=%s' % spl)
if spl is not None:
if len(spl) > 0 and spl[0] != 's':
logging.error("Error URL \"%s\" is not a story." % self.url)
exit (20)
if len(spl) > 1:
self.storyId = spl[1]
if len(spl) > 2:
chapter = spl[1]
else:
chapter = '1'
if len(spl) == 5:
self.path = "/".join(spl[1:-1])
self.outputName = spl[4] + '-ffnet_' + spl[2]
if self.path.endswith('/'):
self.path = self.path[:-1]
logging.debug('self.path=%s' % self.path)
(s, self.storyId, chapter) = self.path.split('/')
self.uuid = 'urn:uuid:' + self.host + '-u.' + self.authorId + '-s.' + self.storyId
logging.debug('self.uuid=%s' % self.uuid)
@ -190,12 +198,14 @@ class FFNet(FanfictionSiteAdapter):
if l.find("&#187;") != -1 and l.find('<b>') != -1:
s2 = bs.BeautifulStoneSoup(l)
self.storyName = str(s2.find('b').string)
logging.debug('self.storyId=%s self.storyName=%s' % (self.storyId, self.storyName))
# mangling storyName replaces url for outputName
self.outputName = self.storyName.replace(" ", "_") + '-ffnet_' + self.storyId
logging.debug('self.storyId=%s, self.storyName=%s, self.outputName=%s' % (self.storyId, self.storyName, self.outputName))
elif l.find("<a href='/u/") != -1:
s2 = bs.BeautifulStoneSoup(l)
self.authorName = str(s2.a.string)
(u1, u2, self.authorId, u3) = s2.a['href'].split('/')
logging.debug('self.authorId=%s self.authorName=%s' % (self.authorId, self.authorName))
logging.debug('self.authorId=%s, self.authorName=%s' % (self.authorId, self.authorName))
elif l.find("Rated: <a href=") != -1:
s2 = bs.BeautifulStoneSoup(l)
self.storyRating = str(s2.a.string).strip()
@ -321,6 +331,10 @@ class FFNet(FanfictionSiteAdapter):
def setPassword(self, password):
self.password = password
def getHost(self):
logging.debug('self.host=%s' % self.host)
return self.host
def getStoryURL(self):
logging.debug('self.url=%s' % self.url)
return self.url

View file

@ -229,6 +229,10 @@ class FictionAlley(FanfictionSiteAdapter):
return result
def getHost(self):
logging.debug('self.host=%s' % self.host)
return self.host
def getStoryName(self):
return self.storyName

View file

@ -229,6 +229,10 @@ class FicWad(FanfictionSiteAdapter):
return result
def getHost(self):
logging.debug('self.host=%s' % self.host)
return self.host
def getStoryName(self):
return self.storyName

View file

@ -198,6 +198,10 @@ class HPFiction(FanfictionSiteAdapter):
return urls
def getHost(self):
logging.debug('self.host=%s' % self.host)
return self.host
def getStoryName(self):
return self.storyName

View file

@ -242,10 +242,29 @@ class EPubFanficWriter(FanficWriter):
else:
description = str(description)
if description is not None and len(description) > 0:
description = description.replace ('\\\'', '').replace('\\\"', '')
description = removeEntities(description.replace('&nbsp;',' ').replace('&rsquo;',''))
else:
description = ' '
### writing content -- title page
titleFilePath = "OEBPS/title_page.xhtml"
self._writeFile(titleFilePath, TITLE_PAGE % (self.authorName, self.storyTitle, self.adapter.getStoryURL(), self.storyTitle, self.adapter.getAuthorURL(), self.authorName, self.adapter.getCategory(), self.adapter.getGenre(), self.adapter.getStoryStatus(), published, updated, createda, self.adapter.getStoryRating(), self.adapter.getStoryUserRating(), self.adapter.getNumChapters(), self.adapter.getNumWords(), self.adapter.getStoryURL(), self.adapter.getStoryURL(), description))
self._writeFile(titleFilePath, TITLE_HEADER % (self.authorName, self.storyTitle, self.adapter.getStoryURL(), self.storyTitle, self.adapter.getAuthorURL(), self.authorName))
self._writeFile(titleFilePath, TITLE_ENTRY % ('Category:', self.adapter.getCategory()))
self._writeFile(titleFilePath, TITLE_ENTRY % ('Genre:', self.adapter.getGenre()))
self._writeFile(titleFilePath, TITLE_ENTRY % ('Status:', self.adapter.getStoryStatus()))
self._writeFile(titleFilePath, TITLE_ENTRY % ('Published:', published))
self._writeFile(titleFilePath, TITLE_ENTRY % ('Updated:', updated))
self._writeFile(titleFilePath, TITLE_ENTRY % ('Packaged:', createda))
tmpstr = self.adapter.getStoryRating() + " / " + self.adapter.getStoryUserRating()
self._writeFile(titleFilePath, TITLE_ENTRY % ('Rating Age/User:', tmpstr))
tmpstr = self.adapter.getNumChapters() + " / " + self.adapter.getNumWords()
self._writeFile(titleFilePath, TITLE_ENTRY % ('Chapters/Words:', tmpstr))
self._writeFile(titleFilePath, TITLE_ENTRY % ('Publisher:', self.adapter.getHost()))
self._writeFile(titleFilePath, TITLE_ENTRY % ('Story ID:', self.adapter.getStoryId()))
self._writeFile(titleFilePath, TITLE_ENTRY % ('Author ID:', self.adapter.getAuthorId()))
self._writeFile(titleFilePath, TITLE_FOOTER % description )
### writing content -- opf file
opfFilePath = "OEBPS/content.opf"

View file

@ -277,6 +277,10 @@ class Twilighted(FanfictionSiteAdapter):
else:
return False
def getHost(self):
logging.debug('self.host=%s' % self.host)
return self.host
def getStoryURL(self):
logging.debug('self.url=%s' % self.url)
return self.url