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