From 009e77c8789b1a43c5c3c4ea237dc4e56e322bd8 Mon Sep 17 00:00:00 2001 From: Mez Date: Sun, 24 Aug 2025 18:16:28 +0100 Subject: [PATCH] Show currently reading books --- generate.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/generate.py b/generate.py index 71340e2..9dc6c47 100644 --- a/generate.py +++ b/generate.py @@ -119,7 +119,7 @@ for file in concernedfiles: status = "existing" readdate = dateobj if status == "new": - thedict = {"id":bookid,"readdates":[readdate],"progressdates":[],"obtaineddate":"","work":False} + thedict = {"id":bookid,"readdates":[readdate],"progressdates":[],"obtaineddate":"","work":False,"progress":100} if "work" in book.tags: thedict["work"] = True books.append(thedict) @@ -134,6 +134,7 @@ for file in concernedfiles: origbook["readdates"].extend(twodict["readdates"]) if twodict["work"]: origbook["work"] = True + origbook["progress"] = 100 if action.heading == "progress": for book in action.children: bookid = book.heading @@ -142,9 +143,13 @@ for file in concernedfiles: bookids.append(bookid) else: status = "existing" + if len(re.findall(r"\*.*%.\*",book.body)) > 0: + theprogress = int((re.findall(r"\*.*%.\*",book.body))[0][1:-3]) + else: + theprogress = 0 progressdate = dateobj if status == "new": - thedict = {"id":bookid,"readdates":[],"progressdates":[progressdate],"obtaineddate":"","work":False} + thedict = {"id":bookid,"readdates":[],"progressdates":[progressdate],"obtaineddate":"","work":False,"progress":theprogress} if "work" in book.tags: thedict["work"] = True books.append(thedict) @@ -159,6 +164,8 @@ for file in concernedfiles: origbook["progressdates"].extend(twodict["progressdates"]) if twodict["work"]: origbook["work"] = True + if theprogress > 0: + origbook["progress"] = theprogress if action.heading == "obtained": for book in action.children: bookid = re.sub(" \(.*\)","",book.heading) @@ -169,7 +176,7 @@ for file in concernedfiles: status = "existing" obtaineddate = dateobj if status == "new": - thedict = {"id":bookid,"readdates":[],"progressdates":[],"obtaineddate":obtaineddate,"work":False} + thedict = {"id":bookid,"readdates":[],"progressdates":[],"obtaineddate":obtaineddate,"work":False,"progress":0} if "work" in book.tags: thedict["work"] = True books.append(thedict) @@ -1209,14 +1216,23 @@ def thisyearbooks(theyear=datetime.today().year): booksthisyear.append(bookdict) booksthisyear = sorted(booksthisyear,key=lambda d: d["date"]) - bookindex.write("\n\n \n \n \n praze • Books\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n
\n
\n

Books read in " + str(theyear) + "

\n") + bookindex.write("\n\n \n \n \n praze • Books\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n
\n
\n

Currently reading

\n
    \n") + for book in books: + if not book["work"]: + if len(book["progressdates"]) > 0: + if len(book["readdates"]) == 0: + if book["author"] == "": + bookindex.write("
  • " + book["title"] + " " + str(book["progress"]) + "%
  • \n") + else: + bookindex.write("
  • " + book["author"] + " – " + book["title"] + " " + str(book["progress"]) + "%
  • \n") + bookindex.write("
\n
\n
\n

Books read in " + str(theyear) + "

\n") if len(booksthisyear) > 0: bookindex.write("
    \n") for book in booksthisyear: if book["author"] == "": bookindex.write("
  1. " + book["title"] + "
  2. \n") else: - bookindex.write("
  3. " + book["author"] + ": " + book["title"] + "
  4. \n") + bookindex.write("
  5. " + book["author"] + " – " + book["title"] + "
  6. \n") bookindex.write("
\n") if workbooks > 1: bookindex.write("

+ " + str(workbooks) + " work-related books

\n")