bar_width = 35
background_color = '#444'
author_color = '#444'
+ default_background = get_resource('res/webtreatsetc-5647576127-ccby.png')
+ format = 'JPEG'
epochs = {
u'Starożytność': 0,
bg_src = urlopen(book_info.cover_url)
self.background_img = StringIO(bg_src.read())
bg_src.close()
+ else:
+ self.background_img = self.default_background
def pretty_author(self):
return self.author.upper()
if not field.multiple:
raise "OUCH!! for field %s" % name
- return value[0]
+ return value[0] if value else None
except (KeyError, AttributeError):
return object.__getattribute__(self, name)
Field( DCNS('audience'), 'audiences', salias='audience', multiple=True,
required=False),
- Field( DCNS('subject.period'), 'epochs', salias='epoch', multiple=True),
- Field( DCNS('subject.type'), 'kinds', salias='kind', multiple=True),
- Field( DCNS('subject.genre'), 'genres', salias='genre', multiple=True),
+ Field( DCNS('subject.period'), 'epochs', salias='epoch', multiple=True,
+ required=False),
+ Field( DCNS('subject.type'), 'kinds', salias='kind', multiple=True,
+ required=False),
+ Field( DCNS('subject.genre'), 'genres', salias='genre', multiple=True,
+ required=False),
Field( DCNS('contributor.translator'), 'translators', \
as_person, salias='translator', multiple=True, default=[]),
Field( DCNS('relation.isVariantOf'), 'variant_of',
WLURI, strict=as_wluri_strict, required=False),
- Field( DCNS('relation.cover_image.url'), 'cover_url', required=False),
- Field( DCNS('relation.cover_image.attribution'), 'cover_by', required=False),
- Field( DCNS('relation.cover_image.source'), 'cover_source', required=False),
+ Field( DCNS('relation.coverImage.url'), 'cover_url', required=False),
+ Field( DCNS('relation.coverImage.attribution'), 'cover_by', required=False),
+ Field( DCNS('relation.coverImage.source'), 'cover_source', required=False),
)
# Process all elements except begin and end
else:
# Omit annotation tags
- if len(element.get('name', '')) or element.get('class', '') == 'annotation':
+ if (len(element.get('name', '')) or
+ element.get('class', '') in ('annotation', 'anchor')):
if event == 'end' and element.tail:
for fragment_id in open_fragments:
open_fragments[fragment_id].append('text', element.tail)
flags = ('less-advertising',)
-class VirtualoEpubPackager(Packager):
+class VirtualoPackager(Packager):
@staticmethod
def utf_trunc(text, limit):
""" truncates text to at most `limit' bytes in utf-8 """
cover.VirtualoCover(info).save(os.path.join(outfile_dir, slug+'.jpg'))
outfile = os.path.join(outfile_dir, '1.epub')
outfile_sample = os.path.join(outfile_dir, '1.sample.epub')
- doc.save_output_file(epub.transform(doc),
+ doc.save_output_file(doc.as_epub(),
output_path=outfile)
- doc.save_output_file(epub.transform(doc, sample=25),
+ doc.save_output_file(doc.as_epub(doc, sample=25),
+ output_path=outfile_sample)
+ outfile = os.path.join(outfile_dir, '1.mobi')
+ outfile_sample = os.path.join(outfile_dir, '1.sample.mobi')
+ doc.save_output_file(doc.as_mobi(cover=cover.VirtualoCover),
+ output_path=outfile)
+ doc.save_output_file(
+ doc.as_mobi(doc, cover=cover.VirtualoCover, sample=25),
output_path=outfile_sample)
except ParseError, e:
print '%(file)s:%(name)s:%(message)s' % {
if options.verbose:
print input_filename
- output_filename = os.path.splitext(input_filename)[0] + '.png'
+ output_filename = os.path.splitext(input_filename)[0] + '.jpg'
doc = WLDocument.from_file(input_filename)
WLCover(doc.book_info).save(output_filename)
help='print status messages to stdout')
parser.add_option('-i', '--ignore-dublin-core', action='store_false', dest='parse_dublincore', default=True,
help='don\'t try to parse dublin core metadata')
+ parser.add_option('-r', '--raw', action='store_false', dest='full_page', default=True,
+ help='outpu raw text for use in templates')
options, input_filenames = parser.parse_args()
try:
doc = WLDocument.from_file(input_filename,
parse_dublincore=options.parse_dublincore)
- html = doc.as_html(flags=('full-page',))
+ flags = ('full-page',) if options.full_page else None
+ html = doc.as_html(flags=flags)
doc.save_output_file(html, output_path=output_filename)
except ParseError, e:
print '%(file)s:%(name)s:%(message)s' % {
if options.gandalf_pdf:
packagers.GandalfPdfPackager.prepare(input_filenames, options.output_dir, options.verbose)
if options.virtualo:
- packagers.VirtualoEpubPackager.prepare(input_filenames, options.output_dir, options.verbose)
+ packagers.VirtualoPackager.prepare(input_filenames, options.output_dir, options.verbose)
if options.prestigio:
packagers.PrestigioEpubPackager.prepare(input_filenames, options.output_dir, options.verbose)
if options.prestigio_pdf: