Add pages listing books read in previous years

This commit is contained in:
mez 2025-08-24 21:29:17 +01:00
parent 009e77c878
commit 99ea2cae65

View file

@ -1199,23 +1199,30 @@ def bookfeed():
feedwrite.close()
def thisyearbooks(theyear=datetime.today().year):
bookindex = open("build/books/index.html","w")
booksthisyear = []
workbooks = 0
for book in books:
for date in book["readdates"]:
if date.year == theyear:
if book["work"]:
workbooks += 1
else:
if not book["work"]:
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"])
return booksthisyear
def thisyearworkbooks(theyear=datetime.today().year):
workbooks = 0
for book in books:
for date in book["readdates"]:
if date.year == theyear:
if book["work"]:
workbooks += 1
return workbooks
def booksfrontpage():
bookindex = open("build/books/index.html","w")
bookindex.write("<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>praze • Books</title>\n <meta property=\"og:title\" content=\"praze • Books\">\n <meta property=\"og:type\" content=\"website\">\n <meta property=\"og:image\" content=\"https://tre.praze.net/ab.png\">\n <meta property=\"og:url\" content=\"https://tre.praze.net/trackers/books\">\n <meta name=\"description\" property=\"og:description\" content=\"Books I have read this year.\">\n <meta property=\"og:locale\" content=\"en_GB\">\n <meta property=\"og:site_name\" content=\"tre.praze.net\">\n <meta name=\"fediverse:creator\" content=\"@tre@praze.net\">\n <link rel=\"webmention\" href=\"https://webmention.io/tre.praze.net/webmention\">\n <link rel=\"me\" href=\"https://kes.praze.net/@tre\">\n <link rel=\"alternate\" type=\"application/rss+xml\" title=\"tre.praze.net\" href=\"/feed.xml\">\n <meta name=\"theme-color\" content=\"#f2f2f2\">\n <link rel=\"stylesheet\" href=\"/new.css\">\n </head>\n <body>\n <nav>\n <input type=\"checkbox\" id=\"toggle\" name=\"toggle\">\n <label class=\"toggle-btn\" for=\"toggle\">Menu</label>\n <ul>\n <li>Fundamentals\n <ul>\n <li><a href=\"/\">Home</a></li>\n <li><a href=\"/about\">About + listings</a></li>\n <li><a href=\"/follow\">Follow</a></li>\n <li><a href=\"/feed.xml\">Changelog</a> <a href=\"/feed.xml\"><span class=\"rss\"></span></a></li>\n <li><a href=\"/sitemap\">Sitemap</a></li>\n <li><a href=\"/siteroll\">Siteroll</a></li>\n </ul>\n </li>\n <li>Projects\n <ul>\n <li><a href=\"/fic\">Fanfiction</a> <a href=\"/fic/feed.xml\"><span class=\"rss\"></span></a></li>\n <li><a href=\"/music\">Music</a></li>\n <li><a href=\"/notes\">Journal</a></li>\n <li>Trackers</li>\n <li><a href=\"https://git.praze.net/tre\" target=\"_blank\">Code</a> <a href=\"https://git.praze.net/tre.rss\"><span class=\"rss\"></span></a></li>\n <li><a href=\"https://img.praze.net\" target=\"_blank\">Photos</a> <a href=\"https://img.praze.net/feed.php\"><span class=\"rss\"></span></a></li>\n </ul>\n </li>\n <li>Fan content\n <ul>\n <li><a href=\"/ffx\">FFX</a></li>\n <li><a href=\"/xvi\">FF16</a></li>\n <li><a href=\"https://morgan.praze.net\" target=\"_blank\">Dermot Morgan</a> <a href=\"https://morgan.praze.net/feed.xml\"><span class=\"rss\"></span></a></li>\n </ul>\n </li>\n <li>Misc.\n <ul>\n <li><a href=\"https://tcg.praze.net\" target=\"_blank\">TCG</a></li>\n <li><a href=\"https://links.praze.net\" target=\"_blank\">Bookmarks</a> <a href=\"https://links.praze.net/feed/rss\"><span class=\"rss\"></span></a></li>\n <li><a href=\"https://kes.praze.net/@tre\" target=\"_blank\">Fediverse</a> <a href=\"https://kes.praze.net/@tre/feed.rss\"><span class=\"rss\"></span></a></li>\n </ul>\n </li>\n </ul>\n </nav>\n <div>\n <main>\n <section>\n <h2>Currently reading</h2>\n<ul>\n")
for book in books:
if not book["work"]:
@ -1225,27 +1232,50 @@ def thisyearbooks(theyear=datetime.today().year):
bookindex.write("<li><i>" + book["title"] + "</i> <progress value=\"" + str(book["progress"]) + "\" max=\"100\" title=\"" + str(book["progress"]) + "%\">" + str(book["progress"]) + "%</progress></li>\n")
else:
bookindex.write("<li>" + book["author"] + "&nbsp;– <i>" + book["title"] + "</i> <progress value=\"" + str(book["progress"]) + "\" max=\"100\" title=\"" + str(book["progress"]) + "%\">" + str(book["progress"]) + "%</progress></li>\n")
bookindex.write("</ul>\n </section>\n <section>\n <h2>Books read in " + str(theyear) + "</h2>\n")
if len(booksthisyear) > 0:
bookindex.write("</ul>\n </section>\n <section>\n <h2>Books read in " + str(datetime.today().year) + "</h2>\n")
if len(thisyearbooks()) > 0:
bookindex.write("<ol>\n")
for book in booksthisyear:
for book in thisyearbooks():
if book["author"] == "":
bookindex.write("<li><i>" + book["title"] + "</i></li>\n")
else:
bookindex.write("<li>" + book["author"] + "&nbsp;– <i>" + book["title"] + "</i></li>\n")
bookindex.write("</ol>\n")
if workbooks > 1:
bookindex.write("<p>+ " + str(workbooks) + " work-related books</p>\n")
elif workbooks == 1:
if thisyearworkbooks() > 1:
bookindex.write("<p>+ " + str(thisyearworkbooks()) + " work-related books</p>\n")
elif thisyearworkbooks() == 1:
bookindex.write("<p>+ 1 work-related book</p>\n")
if len(booksthisyear) == 0 and workbooks == 0:
if len(thisyearbooks()) == 0 and thisyearworkbooks() == 0:
bookindex.write("<p>None yet!</p>\n")
bookindex.write("</section>\n </main>\n <footer>\n <ul>\n <li><a href=\"/trackers\">back to trackers</a></li>\n </ul>\n </footer>\n </div>\n <a href=\"/\"><img src=\"/a.png\" style=\"position:fixed;bottom:2px;right:2px;\" title=\"home\"></a></body>\n</html>\n")
bookindex.close()
def previousyearbooks():
theyear = datetime.today().year - 1
while theyear > 1993:
if len(thisyearbooks(theyear)) > 0:
if not os.path.isdir("build/books/" + str(theyear)):
os.mkdir("build/books/" + str(theyear))
booksyear = open("build/books/" + str(theyear) + "/index.html","w")
booksyear.write("<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>praze • Books</title>\n <meta property=\"og:title\" content=\"praze • Books\">\n <meta property=\"og:type\" content=\"website\">\n <meta property=\"og:image\" content=\"https://tre.praze.net/ab.png\">\n <meta property=\"og:url\" content=\"https://tre.praze.net/trackers/books/" + str(theyear) + "\">\n <meta name=\"description\" property=\"og:description\" content=\"Books I read in " + str(theyear) + ".\">\n <meta property=\"og:locale\" content=\"en_GB\">\n <meta property=\"og:site_name\" content=\"tre.praze.net\">\n <meta name=\"fediverse:creator\" content=\"@tre@praze.net\">\n <link rel=\"webmention\" href=\"https://webmention.io/tre.praze.net/webmention\">\n <link rel=\"me\" href=\"https://kes.praze.net/@tre\">\n <link rel=\"alternate\" type=\"application/rss+xml\" title=\"tre.praze.net\" href=\"/feed.xml\">\n <meta name=\"theme-color\" content=\"#f2f2f2\">\n <link rel=\"stylesheet\" href=\"/new.css\">\n </head>\n <body>\n <nav>\n <input type=\"checkbox\" id=\"toggle\" name=\"toggle\">\n <label class=\"toggle-btn\" for=\"toggle\">Menu</label>\n <ul>\n <li>Fundamentals\n <ul>\n <li><a href=\"/\">Home</a></li>\n <li><a href=\"/about\">About + listings</a></li>\n <li><a href=\"/follow\">Follow</a></li>\n <li><a href=\"/feed.xml\">Changelog</a> <a href=\"/feed.xml\"><span class=\"rss\"></span></a></li>\n <li><a href=\"/sitemap\">Sitemap</a></li>\n <li><a href=\"/siteroll\">Siteroll</a></li>\n </ul>\n </li>\n <li>Projects\n <ul>\n <li><a href=\"/fic\">Fanfiction</a> <a href=\"/fic/feed.xml\"><span class=\"rss\"></span></a></li>\n <li><a href=\"/music\">Music</a></li>\n <li><a href=\"/notes\">Journal</a></li>\n <li>Trackers</li>\n <li><a href=\"https://git.praze.net/tre\" target=\"_blank\">Code</a> <a href=\"https://git.praze.net/tre.rss\"><span class=\"rss\"></span></a></li>\n <li><a href=\"https://img.praze.net\" target=\"_blank\">Photos</a> <a href=\"https://img.praze.net/feed.php\"><span class=\"rss\"></span></a></li>\n </ul>\n </li>\n <li>Fan content\n <ul>\n <li><a href=\"/ffx\">FFX</a></li>\n <li><a href=\"/xvi\">FF16</a></li>\n <li><a href=\"https://morgan.praze.net\" target=\"_blank\">Dermot Morgan</a> <a href=\"https://morgan.praze.net/feed.xml\"><span class=\"rss\"></span></a></li>\n </ul>\n </li>\n <li>Misc.\n <ul>\n <li><a href=\"https://tcg.praze.net\" target=\"_blank\">TCG</a></li>\n <li><a href=\"https://links.praze.net\" target=\"_blank\">Bookmarks</a> <a href=\"https://links.praze.net/feed/rss\"><span class=\"rss\"></span></a></li>\n <li><a href=\"https://kes.praze.net/@tre\" target=\"_blank\">Fediverse</a> <a href=\"https://kes.praze.net/@tre/feed.rss\"><span class=\"rss\"></span></a></li>\n </ul>\n </li>\n </ul>\n </nav>\n <div>\n <main>\n <section>\n <h2>Books read in " + str(theyear) + "</h2>\n<ol>\n")
for book in thisyearbooks(theyear):
if book["author"] == "":
booksyear.write("<li><i>" + book["title"] + "</i></li>\n")
else:
booksyear.write("<li>" + book["author"] + "&nbsp;– <i>" + book["title"] + "</i></li>\n")
booksyear.write("</ol>\n")
if thisyearworkbooks(theyear) > 1:
booksyear.write("<p>+ " + str(thisyearworkbooks(theyear)) + " work-related books</p>\n")
elif thisyearworkbooks(theyear) == 1:
booksyear.write("<p>+ 1 work-related book</p>\n")
booksyear.write("</section>\n </main>\n <footer>\n <ul>\n <li><a href=\"/trackers/books\">back to books index</a></li>\n </ul>\n </footer>\n </div>\n <a href=\"/\"><img src=\"/a.png\" style=\"position:fixed;bottom:2px;right:2px;\" title=\"home\"></a></body>\n</html>\n")
booksyear.close()
theyear -= 1
if __name__ == "__main__":
bookfeed()
thisyearbooks()
booksfrontpage()
previousyearbooks()
def filmfeed():
if not os.path.isdir("build/films"):