From 5255206cf4af194e92b56b31f81b47f9bbfd323f Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Tue, 22 Oct 2024 00:41:45 +0200 Subject: [PATCH] Improved events order --- obsidian_import/obsidian.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/obsidian_import/obsidian.py b/obsidian_import/obsidian.py index 6b5a11f..43dcc4f 100644 --- a/obsidian_import/obsidian.py +++ b/obsidian_import/obsidian.py @@ -16,7 +16,7 @@ logger = getLogger(__name__) StatisticKey = str -@dataclasses.dataclass(frozen=True) +@dataclasses.dataclass(frozen=True, order=True) class Event: start_time: datetime.time | None end_time: datetime.time | None @@ -48,6 +48,8 @@ FILE_FORMAT = """ {blocks_post_events} """ +MIDNIGHT = datetime.time(0,0,0) + class ObsidianVault: def __init__(self, vault_path: Path, read_only: bool = 'silent'): @@ -158,7 +160,9 @@ class ObsidianVault: MARKDOWN_RENDERER.render(b) for b in contents.blocks_post_events ) - events = sorted(contents.events, key=lambda x: x.start_time or x.end_time) + events = list(contents.events) + events.sort() + events.sort(key=lambda x: x.start_time or x.end_time or MIDNIGHT) block_events = '\n'.join( '- ' + format_event_string(e) for e in events ) @@ -235,8 +239,7 @@ def format_event_string(event: Event) -> str: buf.append(event.verb) buf.append(' [[') buf.append(event.subject) - buf.append(']].') - buf.append((' ' + event.comment).strip()) + buf.append((']]. ' + event.comment).strip()) return ''.join(buf)