mirror of
https://github.com/wassname/FanFicFare.git
synced 2026-09-10 11:40:24 +08:00
Improved error handling for mobi issues.
This commit is contained in:
@@ -68,3 +68,10 @@ class UnknownSite(Exception):
|
||||
def __str__(self):
|
||||
return "Unknown Site(%s). Supported sites: (%s)" % (self.url, ", ".join(self.supported_sites_list))
|
||||
|
||||
class FailedToWriteOutput(Exception):
|
||||
def __init__(self,error):
|
||||
self.error=error
|
||||
|
||||
def __str__(self):
|
||||
return self.error
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class HtmlProcessor:
|
||||
self.unfill = unfill
|
||||
html = self._ProcessRawHtml(html)
|
||||
self._soup = BeautifulSoup(html)
|
||||
if self._soup.title:
|
||||
if self._soup.title.contents:
|
||||
self.title = self._soup.title.contents[0]
|
||||
else:
|
||||
self.title = None
|
||||
|
||||
@@ -8,6 +8,8 @@ import time
|
||||
import random
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from html import HtmlProcessor
|
||||
|
||||
# http://wiki.mobileread.com/wiki/MOBI
|
||||
@@ -124,8 +126,8 @@ class Converter:
|
||||
tmp = self.MakeOneHTML(html_strs)
|
||||
self._ConvertStringToFile(tmp, out_file)
|
||||
except Exception, e:
|
||||
logging.error('Error %s', e)
|
||||
logging.debug('Details: %s' % html_strs)
|
||||
logger.error('Error %s', e)
|
||||
#logger.debug('Details: %s' % html_strs)
|
||||
|
||||
def _ConvertStringToFile(self, html_data, out):
|
||||
html = HtmlProcessor(html_data)
|
||||
|
||||
@@ -22,6 +22,9 @@ import StringIO
|
||||
from base_writer import *
|
||||
from ..htmlcleanup import stripHTML
|
||||
from ..mobi import Converter
|
||||
from ..exceptions import FailedToWriteOutput
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class MobiWriter(BaseStoryWriter):
|
||||
|
||||
@@ -160,7 +163,7 @@ ${value}<br />
|
||||
|
||||
for index, (title,html) in enumerate(self.story.getChapters()):
|
||||
if html:
|
||||
logging.debug('Writing chapter text for: %s' % title)
|
||||
logger.debug('Writing chapter text for: %s' % title)
|
||||
vals={'chapter':title, 'index':"%04d"%(index+1), 'number':index+1}
|
||||
fullhtml = CHAPTER_START.substitute(vals) + html + CHAPTER_END.substitute(vals)
|
||||
# ffnet(& maybe others) gives the whole chapter text
|
||||
@@ -175,6 +178,8 @@ ${value}<br />
|
||||
author=self.getMetadata('author'),
|
||||
publisher=self.getMetadata('site'))
|
||||
mobidata = c.ConvertStrings(files)
|
||||
if len(mobidata) < 1:
|
||||
raise FailedToWriteOutput("Zero length mobi output")
|
||||
out.write(mobidata)
|
||||
|
||||
del files
|
||||
|
||||
Reference in New Issue
Block a user