forming up the interface

This commit is contained in:
cellarspoon 2021-11-29 11:57:13 +01:00
parent b191808a13
commit 5d2ba100cf
No known key found for this signature in database
GPG Key ID: 03789458B3D0C410
2 changed files with 47 additions and 33 deletions

View File

@ -0,0 +1,10 @@
# temp-index
## hacking
```python
from temp_index import make_cards
make_cards("mycards.pdf", "sqlite:///metadata.db", ["title"])
```

View File

@ -7,54 +7,58 @@ from reportlab.pdfgen import canvas
from reportlab.platypus import PageBreak, Paragraph, SimpleDocTemplate, Spacer
def make_cards():
def make_cards(filename, db_path, fields):
"""The main entrypoint for card generation."""
# TODO: thread arguments into this logic
doc = create_doc("text.pdf")
content = get_fields()
doc = create_doc(filename)
content = get_fields(db_path, fields)
doc.build(content)
def get_fields():
def get_fields(db_path, fields):
"""Retrieve fields from the metadata."""
content = []
styles = getSampleStyleSheet()
session = init_session("sqlite:///metadata.db")
session = init_session(db_path)
for book in session.query(Book).all():
for comment in session.query(Comment).all():
ptitle = Paragraph(
"<font size=12>{}</font>".format(book.title), styles["Italic"]
)
ptime = Paragraph(
"<font size=10>Uploaded: {}</font>".format(book.timestamp),
styles["Normal"],
)
pcomments = Paragraph("<font size=10>{}</font>".format(comment.text))
format_string = "<font size=12>{}</font>"
all_authors = [author.name for author in book.authors]
glued_together = format_string.format(", ".join(all_authors))
if "title" in fields:
tag = "<font size=12>{}</font>".format(book.title)
ptitle = Paragraph(tag, styles["Italic"])
content.append(ptitle)
content.append(Spacer(1, 12))
format_string = "<font size=10>{}</font>"
all_tags = [tag.name for tag in book.tags]
tags_glued_together = format_string.format(", ".join(all_tags))
if "uploaded_at" in fields:
tag = "<font size=10>Uploaded: {}</font>".format(book.timestamp)
ptime = Paragraph(tag, styles["Normal"])
content.append(ptime)
content.append(Spacer(1, 12))
content.append(ptitle)
content.append(Spacer(1, 12))
content.append(ptime)
content.append(Spacer(1, 12))
content.append(pcomments)
if "comments" in fields:
tag = "<font size=10>{}</font>".format(comment.text)
pcomments = Paragraph(tag)
content.append(pcomments)
p = Paragraph(glued_together, styles["Normal"])
content.append(p)
content.append(PageBreak())
content.append(Spacer(6, 12))
if "authors" in fields:
format_string = "<font size=12>{}</font>"
all_authors = [author.name for author in book.authors]
glued_together = format_string.format(", ".join(all_authors))
p = Paragraph(tags_glued_together, styles["Normal"])
content.append(p)
content.append(PageBreak())
content.append(Spacer(6, 12))
p = Paragraph(glued_together, styles["Normal"])
content.append(p)
content.append(PageBreak())
content.append(Spacer(6, 12))
if "tags" in fields:
format_string = "<font size=10>{}</font>"
all_tags = [tag.name for tag in book.tags]
tags_glued_together = format_string.format(", ".join(all_tags))
p = Paragraph(tags_glued_together, styles["Normal"])
content.append(p)
content.append(PageBreak())
content.append(Spacer(6, 12))
return content