only count books I finished
authorAlex Chan <alex@alexwlchan.net>
Mon, 5 Jul 2021 20:12:03 +0000 (21:12 +0100)
committerAlex Chan <alex@alexwlchan.net>
Mon, 5 Jul 2021 20:12:03 +0000 (21:12 +0100)
scripts/render_html.py
templates/list_reviews.html

index d4ea896..e65e9da 100755 (executable)
@@ -8,6 +8,7 @@ import pathlib
 import re
 import subprocess
 import sys
+import typing
 
 import attr
 import bs4
@@ -92,6 +93,10 @@ class Review:
     rating = attr.ib(default=None)
     did_not_finish = attr.ib(default=False)
 
+    @property
+    def finished(self):
+        return not self.did_not_finish
+
 
 @attr.s
 class ReviewEntry:
@@ -287,6 +292,10 @@ def css_hash(_):
     return f"md5:{CSS_HASH}"
 
 
+def count_finished_books(review_entries: typing.List[ReviewEntry]):
+    return len([r for r in review_entries if r.review.finished])
+
+
 def main():
     set_git_timestamps()
 
@@ -302,6 +311,7 @@ def main():
     env.filters["css_hash"] = css_hash
     env.filters["create_shelf_data_uri"] = create_shelf_data_uri
     env.filters["cap_rgb"] = lambda v: min([v, 255])
+    env.filters["count_finished_books"] = count_finished_books
 
     create_thumbnails()
 
index ec664c0..5b87945 100644 (file)
@@ -22,7 +22,7 @@
   <div class="divider"><img src="/static/book.svg"></div>
 
   <div class="books_by_year" id="books_by_year_{{ year }}">
-    <h3>the {{ reviews|length }} book{% if reviews|length != 1 %}s{% endif %}
+    <h3>the {{ reviews|count_finished_books }} book{% if reviews|count_finished_books != 1 %}s{% endif %}
       {% if year == this_year %}
         i&rsquo;ve read so far
       {% else %}