1
0

Improved events order
Some checks failed
Run Python tests (through Pytest) / Test (push) Failing after 33s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 29s

This commit is contained in:
Jon Michael Aanes 2024-10-22 00:41:45 +02:00
parent be0a30298d
commit 5255206cf4
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -16,7 +16,7 @@ logger = getLogger(__name__)
StatisticKey = str StatisticKey = str
@dataclasses.dataclass(frozen=True) @dataclasses.dataclass(frozen=True, order=True)
class Event: class Event:
start_time: datetime.time | None start_time: datetime.time | None
end_time: datetime.time | None end_time: datetime.time | None
@ -48,6 +48,8 @@ FILE_FORMAT = """
{blocks_post_events} {blocks_post_events}
""" """
MIDNIGHT = datetime.time(0,0,0)
class ObsidianVault: class ObsidianVault:
def __init__(self, vault_path: Path, read_only: bool = 'silent'): 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 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( block_events = '\n'.join(
'- ' + format_event_string(e) for e in events '- ' + 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(event.verb)
buf.append(' [[') buf.append(' [[')
buf.append(event.subject) buf.append(event.subject)
buf.append(']].') buf.append((']]. ' + event.comment).strip())
buf.append((' ' + event.comment).strip())
return ''.join(buf) return ''.join(buf)