diff --git a/action.py b/action.py index 3c1ee95..82febb5 100644 --- a/action.py +++ b/action.py @@ -4,8 +4,10 @@ from functools import partial import io import json +import os import re import sys +import time from zoneinfo import ZoneInfo from PyQt5.Qt import QUrl # pylint: disable=no-name-in-module @@ -273,11 +275,11 @@ def get_sidecar(self, device, path): return None debug_print('parsing {}'.format(path)) - parsed_contents = self.parse_sidecar_lua(decoded_contents) + parsed_contents = self.parse_sidecar_lua(decoded_contents, path) return parsed_contents - def parse_sidecar_lua(self, sidecar_lua): + def parse_sidecar_lua(self, sidecar_lua, path): """Parses a sidecar Lua file into a Python dict :param sidecar_lua: the contents of a sidecar Lua as a str @@ -311,6 +313,15 @@ def parse_sidecar_lua(self, sidecar_lua): 'last_bookmark': max(bookmark_dates), } + if os.path.exists(path): + modify_time = os.path.getmtime(path) + last_read = time.strftime('%Y-%m-%d %H:%M:%S', + time.localtime(modify_time)) + if 'calculated' not in decoded_lua.keys(): + decoded_lua['calculated'] = {} + + decoded_lua['calculated']['last_read_date'] = last_read + return decoded_lua def update_metadata(self, uuid, keys_values_to_update): diff --git a/config.py b/config.py index de7c0f0..2d77ab9 100644 --- a/config.py +++ b/config.py @@ -48,6 +48,13 @@ 'stopped reading at.', 'type': 'text', 'sidecar_property': ['last_xpointer'], +}, { + 'name': 'column_last_read_date', + 'label': 'Last read date column:', + 'tooltip': 'A “Date” column to store the date on which the book was last\n' + 'read. (based on the modify date of the KOReader metadata file)', + 'type': 'datetime', + 'sidecar_property': ['calculated', 'last_read_date'] }, { 'name': 'column_rating', 'label': 'Rating column:',