diff --git a/leech.py b/leech.py index 2d8fd04..e1a224b 100755 --- a/leech.py +++ b/leech.py @@ -3,6 +3,7 @@ import argparse import sys import json +import datetime import sites import epub @@ -41,6 +42,30 @@ cover_template = ''' ''' +frontmatter_template = ''' + + + Front Matter + + + +
+

{title}
By {author}

+
+
Source
+
{unique_id}
+
Started
+
{started:%Y-%m-%d}
+
Updated
+
{updated:%Y-%m-%d}
+
Downloaded on
+
{now:%Y-%m-%d}
+
+
+ + +''' + def leech(url, filename=None, cache=True, args=None): # we have: a page, which could be absolutely any part of a story, or not a story at all @@ -69,15 +94,24 @@ def leech(url, filename=None, cache=True, args=None): 'started': min(dates), 'updated': max(dates), } + + # The cover is static, and the only change comes from the image which we generate html = [('Cover', 'cover.html', cover_template)] - for i, chapter in enumerate(story['chapters']): - html.append((chapter[0], 'chapter%d.html' % (i + 1), html_template.format(title=chapter[0], text=chapter[1]))) + cover_image = ('images/cover.png', cover.make_cover(story['title'], story['author']).read(), 'image/png') + + html.append(('Front Matter', 'frontmatter.html', frontmatter_template.format(now=datetime.datetime.now(), **metadata))) + + for i, (chapter_title, chapter_html, chapter_date) in enumerate(story['chapters']): + html.append(( + chapter_title, + 'chapter%d.html' % (i + 1), + html_template.format(title=chapter_title, text=chapter_html) + )) if 'footnotes' in story and story['footnotes']: html.append(("Footnotes", 'footnotes.html', html_template.format(title="Footnotes", text=story['footnotes']))) css = ('Styles/base.css', fetch('https://raw.githubusercontent.com/mattharrison/epub-css-starter-kit/master/css/base.css'), 'text/css') - cover_image = ('images/cover.png', cover.make_cover(story['title'], story['author']).read(), 'image/png') filename = filename or story['title'] + '.epub'