|
@ -1,5 +1,8 @@ |
|
|
"""Generates PDF cards from a calibre metadata.db.""" |
|
|
"""Generates PDF cards from a calibre metadata.db.""" |
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
|
|
|
import shutil |
|
|
|
|
|
from pathlib import Path |
|
|
from textwrap import shorten |
|
|
from textwrap import shorten |
|
|
|
|
|
|
|
|
from calibrestekje import Book, Comment, Publisher, init_session |
|
|
from calibrestekje import Book, Comment, Publisher, init_session |
|
@ -8,12 +11,16 @@ from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet |
|
|
from reportlab.pdfgen import canvas |
|
|
from reportlab.pdfgen import canvas |
|
|
from reportlab.platypus import PageBreak, Paragraph, SimpleDocTemplate, Spacer |
|
|
from reportlab.platypus import PageBreak, Paragraph, SimpleDocTemplate, Spacer |
|
|
|
|
|
|
|
|
|
|
|
CWD = Path().resolve() |
|
|
|
|
|
|
|
|
def make_cards(filename, db_path, fields): |
|
|
|
|
|
|
|
|
def make_cards(filepath, db_path, fields): |
|
|
"""The main entrypoint for card generation.""" |
|
|
"""The main entrypoint for card generation.""" |
|
|
|
|
|
filename = os.path.basename(filepath) |
|
|
doc = create_doc(filename) |
|
|
doc = create_doc(filename) |
|
|
content = get_fields(db_path, fields) |
|
|
content = get_fields(db_path, fields) |
|
|
doc.build(content) |
|
|
doc.build(content) |
|
|
|
|
|
shutil.move(os.path.join(CWD, filename), filepath) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_fields(db_path, fields): |
|
|
def get_fields(db_path, fields): |
|
@ -29,8 +36,8 @@ def get_fields(db_path, fields): |
|
|
content.append(ptitle) |
|
|
content.append(ptitle) |
|
|
content.append(Spacer(1, 12)) |
|
|
content.append(Spacer(1, 12)) |
|
|
|
|
|
|
|
|
if "uploaded_at" in fields: |
|
|
if "timestamp" in fields: |
|
|
tag = "<font size=10>Uploaded: {}</font>".format(book.timestamp) |
|
|
tag = "<font size=10>Timestamp: {}</font>".format(book.timestamp) |
|
|
ptime = Paragraph(tag, styles["Normal"]) |
|
|
ptime = Paragraph(tag, styles["Normal"]) |
|
|
content.append(ptime) |
|
|
content.append(ptime) |
|
|
content.append(Spacer(1, 12)) |
|
|
content.append(Spacer(1, 12)) |
|
|