argument changes

This commit is contained in:
cellarspoon 2021-12-06 11:37:32 +01:00
parent a8b3e4f9b8
commit 7ab727bf7c
No known key found for this signature in database
GPG Key ID: 03789458B3D0C410
3 changed files with 13 additions and 6 deletions

View File

@ -15,8 +15,8 @@ from temp_index import make_cards
make_cards( make_cards(
"catalogue.pdf", "/home/me/catalogue.pdf",
"sqlite:///metadata.db", "sqlite:///metadata.db",
["title", "uploaded_at", "comments", "authors", "tags"] ["title", "timestamp", "comments", "authors", "tags"]
) )
``` ```

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "temp-index" name = "temp-index"
version = "0.1.0" version = "0.2.0"
description = "" description = ""
authors = ["automatist", "simoon", "decentral1se"] authors = ["automatist", "simoon", "decentral1se"]

View File

@ -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))