From 080d1e0d29f3680c2c24d44156ac82a4745d0c93 Mon Sep 17 00:00:00 2001 From: simoon Date: Mon, 29 Nov 2021 10:45:46 +0100 Subject: [PATCH] added temp_index.py --- temp_index.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 temp_index.py diff --git a/temp_index.py b/temp_index.py new file mode 100644 index 0000000..b416026 --- /dev/null +++ b/temp_index.py @@ -0,0 +1,79 @@ +from reportlab.lib.pagesizes import * +from reportlab.pdfgen import canvas +from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak +from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle +from calibrestekje import Book, Publisher, Comment, init_session + +pagewidth, pageheight = landscape(A6) + +doc = SimpleDocTemplate("text.pdf", pagesize=landscape(A6), + rightMargin=18, leftMargin=18, + topMargin=0, bottomMargin=18) + +content = [] +styles = getSampleStyleSheet() + +session = init_session("sqlite:///metadata.db") + +# if book id from book table is the same as book id from comment table, show me that +for book in session.query(Book).all(): + for comment in session.query(Comment).all(): + if (book.id) == (comment.book): + print (book.id) + print (book.title) + print (book.authors) + print (book.timestamp) + print (book.path) + print (book.tags) + print (comment.text) + + + # create a paragraph and append content to it - e.g. book.title, book.authors etc + ptitle = Paragraph('{}'.format(book.title), styles["Italic"]) + ptime = Paragraph('Uploaded: {}'.format(book.timestamp), styles["Normal"]) + pcomments = Paragraph('{}'.format(comment.text)) + + # list comprehensions for authors and tags + format_string = '{}' + all_authors = [author.name for author in book.authors] + glued_together = format_string.format(", ".join(all_authors)) + + format_string = '{}' + all_tags = [tag.name for tag in book.tags] + tags_glued_together = format_string.format(", ".join(all_tags)) + + # format_string = '{}' + # all_comments = [comment.name for comment in comment.text] + # comments_split_apart = format_string.format("".split(all_comments)[:50]) + + # import ipdb; ipdb.set_trace() + + # append the other content + content.append(ptitle) + content.append(Spacer(1, 12)) + content.append(ptime) + content.append(Spacer(1, 12)) + content.append(pcomments) + + # alternative way to list multiple authors... (without list comprehensions) + # first = True + # author_text = "" + # for author in book.authors: + # if not first: + # author_text += ", " + # author_text += author.name + # first = False + # author_text = "{}".format(author_text) + + # gluing together authors, tags + p = Paragraph(glued_together, styles["Normal"]) + content.append(p) + content.append(PageBreak()) + content.append(Spacer(6, 12)) + + p = Paragraph(tags_glued_together, styles["Normal"]) + content.append(p) + content.append(PageBreak()) + content.append(Spacer(6, 12)) + +doc.build(content) \ No newline at end of file