Browse Source

forming up the interface

main
cellarspoon 3 years ago
parent
commit
5d2ba100cf
No known key found for this signature in database GPG Key ID: 3789458B3D0C410
  1. 10
      README.md
  2. 80
      temp_index.py

10
README.md

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

80
temp_index.py

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

Loading…
Cancel
Save