refac: CalDAV.get_events
This commit is contained in:
parent
0a5f84eee5
commit
ec85614b51
1 changed files with 10 additions and 11 deletions
|
@ -1,10 +1,11 @@
|
|||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
from typing import cast
|
||||
|
||||
from asyncify import asyncify
|
||||
from cache import AsyncTTL
|
||||
from caldav import Calendar, DAVClient, Event, Principal
|
||||
from vobject.base import Component
|
||||
from vobject.base import Component, toVName
|
||||
|
||||
from .calevent import CalEvent
|
||||
from .config import Config
|
||||
|
@ -73,15 +74,13 @@ class CalDAV:
|
|||
|
||||
_logger.info(f"downloading {calendar_name!r} ...")
|
||||
|
||||
search_span = timedelta(days=cfg.calendar.future_days)
|
||||
calendar = cls.principal.calendar(calendar_name)
|
||||
dt_start = datetime.combine(
|
||||
datetime.utcnow().date(),
|
||||
datetime.min.time(),
|
||||
)
|
||||
dt_end = dt_start + timedelta(days=cfg.calendar.future_days)
|
||||
|
||||
date_start = datetime.utcnow().date()
|
||||
time_min = datetime.min.time()
|
||||
dt_start = datetime.combine(date_start, time_min)
|
||||
dt_end = dt_start + search_span
|
||||
|
||||
search_result = calendar.search(
|
||||
search_result = cls.principal.calendar(calendar_name).search(
|
||||
start=dt_start,
|
||||
end=dt_end,
|
||||
expand=True,
|
||||
|
@ -91,7 +90,7 @@ class CalDAV:
|
|||
|
||||
vevents = []
|
||||
for event in search_result:
|
||||
vobject: Component = event.vobject_instance # type: ignore
|
||||
vevents.extend(vobject.vevent_list)
|
||||
vobject = cast(Component, event.vobject_instance)
|
||||
vevents.extend(vobject.contents[toVName("vevent")])
|
||||
|
||||
return sorted(CalEvent.from_vevent(vevent) for vevent in vevents)
|
||||
|
|
Loading…
Reference in a new issue