Add function for listing books read in a year
This commit is contained in:
parent
160f503304
commit
7d566c5b85
1 changed files with 100 additions and 54 deletions
154
generate.py
154
generate.py
|
@ -111,58 +111,79 @@ for file in concernedfiles:
|
||||||
for action in node.children:
|
for action in node.children:
|
||||||
if action.heading == "read":
|
if action.heading == "read":
|
||||||
for book in action.children:
|
for book in action.children:
|
||||||
if "work" not in book.tags:
|
bookid = re.sub(" and rated .*","",book.heading)
|
||||||
bookid = re.sub(" and rated .*","",book.heading)
|
if bookid not in bookids:
|
||||||
if bookid not in bookids:
|
status = "new"
|
||||||
status = "new"
|
bookids.append(bookid)
|
||||||
bookids.append(bookid)
|
else:
|
||||||
|
status = "existing"
|
||||||
|
readdate = dateobj
|
||||||
|
if status == "new":
|
||||||
|
thedict = {"id":bookid,"readdates":[readdate],"progressdates":[],"obtaineddate":"","work":False}
|
||||||
|
if "work" in book.tags:
|
||||||
|
thedict["work"] = True
|
||||||
|
books.append(thedict)
|
||||||
|
else:
|
||||||
|
twodict = {"id":bookid,"readdates":[readdate]}
|
||||||
|
if "work" in book.tags:
|
||||||
|
twodict["work"] = True
|
||||||
else:
|
else:
|
||||||
status = "existing"
|
twodict["work"] = False
|
||||||
readdate = dateobj
|
for origbook in books:
|
||||||
if status == "new":
|
if twodict["id"] == origbook["id"]:
|
||||||
thedict = {"id":bookid,"readdates":[readdate],"progressdates":[],"obtaineddate":""}
|
origbook["readdates"].extend(twodict["readdates"])
|
||||||
books.append(thedict)
|
if twodict["work"]:
|
||||||
else:
|
origbook["work"] = True
|
||||||
twodict = {"id":bookid,"readdates":[readdate]}
|
|
||||||
for origbook in books:
|
|
||||||
if twodict["id"] == origbook["id"]:
|
|
||||||
origbook["readdates"].extend(twodict["readdates"])
|
|
||||||
if action.heading == "progress":
|
if action.heading == "progress":
|
||||||
for book in action.children:
|
for book in action.children:
|
||||||
if "work" not in book.tags:
|
bookid = book.heading
|
||||||
bookid = book.heading
|
if bookid not in bookids:
|
||||||
if bookid not in bookids:
|
status = "new"
|
||||||
status = "new"
|
bookids.append(bookid)
|
||||||
bookids.append(bookid)
|
else:
|
||||||
|
status = "existing"
|
||||||
|
progressdate = dateobj
|
||||||
|
if status == "new":
|
||||||
|
thedict = {"id":bookid,"readdates":[],"progressdates":[progressdate],"obtaineddate":"","work":False}
|
||||||
|
if "work" in book.tags:
|
||||||
|
thedict["work"] = True
|
||||||
|
books.append(thedict)
|
||||||
|
else:
|
||||||
|
twodict = {"id":bookid,"progressdates":[progressdate]}
|
||||||
|
if "work" in book.tags:
|
||||||
|
twodict["work"] = True
|
||||||
else:
|
else:
|
||||||
status = "existing"
|
twodict["work"] = False
|
||||||
progressdate = dateobj
|
for origbook in books:
|
||||||
if status == "new":
|
if twodict["id"] == origbook["id"]:
|
||||||
thedict = {"id":bookid,"readdates":[],"progressdates":[progressdate],"obtaineddate":""}
|
origbook["progressdates"].extend(twodict["progressdates"])
|
||||||
books.append(thedict)
|
if twodict["work"]:
|
||||||
else:
|
origbook["work"] = True
|
||||||
twodict = {"id":bookid,"progressdates":[progressdate]}
|
|
||||||
for origbook in books:
|
|
||||||
if twodict["id"] == origbook["id"]:
|
|
||||||
origbook["progressdates"].extend(twodict["progressdates"])
|
|
||||||
if action.heading == "obtained":
|
if action.heading == "obtained":
|
||||||
for book in action.children:
|
for book in action.children:
|
||||||
if "work" not in book.tags:
|
bookid = re.sub(" \(.*\)","",book.heading)
|
||||||
bookid = re.sub(" \(.*\)","",book.heading)
|
if bookid not in bookids:
|
||||||
if bookid not in bookids:
|
status = "new"
|
||||||
status = "new"
|
bookids.append(bookid)
|
||||||
bookids.append(bookid)
|
else:
|
||||||
|
status = "existing"
|
||||||
|
obtaineddate = dateobj
|
||||||
|
if status == "new":
|
||||||
|
thedict = {"id":bookid,"readdates":[],"progressdates":[],"obtaineddate":obtaineddate,"work":False}
|
||||||
|
if "work" in book.tags:
|
||||||
|
thedict["work"] = True
|
||||||
|
books.append(thedict)
|
||||||
|
else:
|
||||||
|
twodict = {"id":bookid,"obtaineddate":[obtaineddate]}
|
||||||
|
if "work" in book.tags:
|
||||||
|
twodict["work"] = True
|
||||||
else:
|
else:
|
||||||
status = "existing"
|
twodict["work"] = False
|
||||||
obtaineddate = dateobj
|
for origbook in books:
|
||||||
if status == "new":
|
if twodict["id"] == origbook["id"]:
|
||||||
thedict = {"id":bookid,"readdates":[],"progressdates":[],"obtaineddate":obtaineddate}
|
origbook["obtaineddate"] = twodict["obtaineddate"]
|
||||||
books.append(thedict)
|
if twodict["work"]:
|
||||||
else:
|
origbook["work"] = True
|
||||||
twodict = {"id":bookid,"obtaineddate":[obtaineddate]}
|
|
||||||
for origbook in books:
|
|
||||||
if twodict["id"] == origbook["id"]:
|
|
||||||
origbook["obtaineddate"] = twodict["obtaineddate"]
|
|
||||||
if node.heading == "films":
|
if node.heading == "films":
|
||||||
for action in node.children:
|
for action in node.children:
|
||||||
if action.heading == "watched":
|
if action.heading == "watched":
|
||||||
|
@ -1150,15 +1171,16 @@ def bookfeed():
|
||||||
eachdate = enddate
|
eachdate = enddate
|
||||||
while eachdate >= startdate:
|
while eachdate >= startdate:
|
||||||
for book in books:
|
for book in books:
|
||||||
if eachdate in book["readdates"]:
|
if not book["work"]:
|
||||||
yearlist.append({"date":eachdate,"author":book["author"],"title":book["title"].replace("&","&"),"action":"Read"})
|
if eachdate in book["readdates"]:
|
||||||
try:
|
yearlist.append({"date":eachdate,"author":book["author"],"title":book["title"].replace("&","&"),"action":"Read"})
|
||||||
if book["progressdates"][0] == eachdate:
|
try:
|
||||||
yearlist.append({"date":eachdate,"author":book["author"],"title":book["title"].replace("&","&"),"action":"Reading"})
|
if book["progressdates"][0] == eachdate:
|
||||||
except:
|
yearlist.append({"date":eachdate,"author":book["author"],"title":book["title"].replace("&","&"),"action":"Reading"})
|
||||||
pass
|
except:
|
||||||
if book["obtaineddate"] == eachdate:
|
pass
|
||||||
yearlist.append({"date":eachdate,"author":book["author"],"title":book["title"].replace("&","&"),"action":"Added"})
|
if book["obtaineddate"] == eachdate:
|
||||||
|
yearlist.append({"date":eachdate,"author":book["author"],"title":book["title"].replace("&","&"),"action":"Added"})
|
||||||
eachdate -= timedelta(days=1)
|
eachdate -= timedelta(days=1)
|
||||||
checkdate = enddate
|
checkdate = enddate
|
||||||
for event in yearlist:
|
for event in yearlist:
|
||||||
|
@ -1169,6 +1191,30 @@ def bookfeed():
|
||||||
feedwrite.write(" </channel>\n</rss>")
|
feedwrite.write(" </channel>\n</rss>")
|
||||||
feedwrite.close()
|
feedwrite.close()
|
||||||
|
|
||||||
|
def thisyearbooks(theyear=datetime.today().year):
|
||||||
|
booksthisyear = []
|
||||||
|
workbooks = 0
|
||||||
|
for book in books:
|
||||||
|
for date in book["readdates"]:
|
||||||
|
if date.year == theyear:
|
||||||
|
if book["work"]:
|
||||||
|
workbooks += 1
|
||||||
|
else:
|
||||||
|
bookdict = {"author":book["author"],"title":book["title"]}
|
||||||
|
for thedate in book["readdates"]:
|
||||||
|
if thedate.year == theyear:
|
||||||
|
bookdict["date"] = thedate
|
||||||
|
booksthisyear.append(bookdict)
|
||||||
|
booksthisyear = sorted(booksthisyear,key=lambda d: d["date"])
|
||||||
|
index = 1
|
||||||
|
for book in booksthisyear:
|
||||||
|
print(str(index) + ". " + book["author"] + ": " + book["title"])
|
||||||
|
index += 1
|
||||||
|
if workbooks > 1:
|
||||||
|
print("+ " + str(workbooks) + " books read for work")
|
||||||
|
elif workbooks == 1:
|
||||||
|
print("+ 1 book read for work")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
bookfeed()
|
bookfeed()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue