From 795e72b1db4eb09a714181af3e5b62e5dc4efe65 Mon Sep 17 00:00:00 2001 From: mez Date: Sun, 27 Apr 2025 16:25:10 +0100 Subject: [PATCH] Exclude work-related books --- generate.py | 93 +++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/generate.py b/generate.py index 59a91a7..d51bdef 100644 --- a/generate.py +++ b/generate.py @@ -111,55 +111,58 @@ for file in concernedfiles: for action in node.children: if action.heading == "read": for book in action.children: - bookid = re.sub(" and rated .*","",book.heading) - if bookid not in bookids: - status = "new" - bookids.append(bookid) - else: - status = "existing" - readdate = dateobj - if status == "new": - thedict = {"id":bookid,"readdates":[readdate],"progressdates":[],"obtaineddate":""} - books.append(thedict) - else: - twodict = {"id":bookid,"readdates":[readdate]} - for origbook in books: - if twodict["id"] == origbook["id"]: - origbook["readdates"].extend(twodict["readdates"]) + if "work" not in book.tags: + bookid = re.sub(" and rated .*","",book.heading) + if bookid not in bookids: + status = "new" + bookids.append(bookid) + else: + status = "existing" + readdate = dateobj + if status == "new": + thedict = {"id":bookid,"readdates":[readdate],"progressdates":[],"obtaineddate":""} + books.append(thedict) + else: + twodict = {"id":bookid,"readdates":[readdate]} + for origbook in books: + if twodict["id"] == origbook["id"]: + origbook["readdates"].extend(twodict["readdates"]) if action.heading == "progress": for book in action.children: - bookid = book.heading - if bookid not in bookids: - status = "new" - bookids.append(bookid) - else: - status = "existing" - progressdate = dateobj - if status == "new": - thedict = {"id":bookid,"readdates":[],"progressdates":[progressdate],"obtaineddate":""} - books.append(thedict) - else: - twodict = {"id":bookid,"progressdates":[progressdate]} - for origbook in books: - if twodict["id"] == origbook["id"]: - origbook["progressdates"].extend(twodict["progressdates"]) + if "work" not in book.tags: + bookid = book.heading + if bookid not in bookids: + status = "new" + bookids.append(bookid) + else: + status = "existing" + progressdate = dateobj + if status == "new": + thedict = {"id":bookid,"readdates":[],"progressdates":[progressdate],"obtaineddate":""} + books.append(thedict) + else: + twodict = {"id":bookid,"progressdates":[progressdate]} + for origbook in books: + if twodict["id"] == origbook["id"]: + origbook["progressdates"].extend(twodict["progressdates"]) if action.heading == "obtained": for book in action.children: - bookid = re.sub(" \(.*\)","",book.heading) - if bookid not in bookids: - status = "new" - bookids.append(bookid) - else: - status = "existing" - obtaineddate = dateobj - if status == "new": - thedict = {"id":bookid,"readdates":[],"progressdates":[],"obtaineddate":obtaineddate} - books.append(thedict) - else: - twodict = {"id":bookid,"obtaineddate":[obtaineddate]} - for origbook in books: - if twodict["id"] == origbook["id"]: - origbook["obtaineddate"] = twodict["obtaineddate"] + if "work" not in book.tags: + bookid = re.sub(" \(.*\)","",book.heading) + if bookid not in bookids: + status = "new" + bookids.append(bookid) + else: + status = "existing" + obtaineddate = dateobj + if status == "new": + thedict = {"id":bookid,"readdates":[],"progressdates":[],"obtaineddate":obtaineddate} + books.append(thedict) + else: + twodict = {"id":bookid,"obtaineddate":[obtaineddate]} + for origbook in books: + if twodict["id"] == origbook["id"]: + origbook["obtaineddate"] = twodict["obtaineddate"] if node.heading == "films": for action in node.children: if action.heading == "watched":