Browse Source

argument changes

main
cellarspoon 3 years ago
parent
commit
7ab727bf7c
No known key found for this signature in database GPG Key ID: 3789458B3D0C410
  1. 4
      README.md
  2. 2
      pyproject.toml
  3. 13
      temp_index.py

4
README.md

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

2
pyproject.toml

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

13
temp_index.py

@ -1,5 +1,8 @@
"""Generates PDF cards from a calibre metadata.db."""
import os
import shutil
from pathlib import Path
from textwrap import shorten
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.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."""
filename = os.path.basename(filepath)
doc = create_doc(filename)
content = get_fields(db_path, fields)
doc.build(content)
shutil.move(os.path.join(CWD, filename), filepath)
def get_fields(db_path, fields):
@ -29,8 +36,8 @@ def get_fields(db_path, fields):
content.append(ptitle)
content.append(Spacer(1, 12))
if "uploaded_at" in fields:
tag = "<font size=10>Uploaded: {}</font>".format(book.timestamp)
if "timestamp" in fields:
tag = "<font size=10>Timestamp: {}</font>".format(book.timestamp)
ptime = Paragraph(tag, styles["Normal"])
content.append(ptime)
content.append(Spacer(1, 12))

Loading…
Cancel
Save