Skip to content

Commit

Permalink
add last_read_date column
Browse files Browse the repository at this point in the history
based on the metadata file modify time
  • Loading branch information
Hyphen-ated committed Nov 6, 2022
1 parent 8daf42c commit 781a4cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 13 additions & 2 deletions action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:',
Expand Down

0 comments on commit 781a4cc

Please sign in to comment.