use properties correctly

This commit is contained in:
Jörn-Michael Miehe 2022-09-04 14:14:22 +00:00
parent 513a577914
commit 559803ac0e

View file

@ -1,6 +1,7 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Iterator from typing import Iterator
import caldav
from fastapi import APIRouter, Depends, HTTPException, status from fastapi import APIRouter, Depends, HTTPException, status
from .. import caldav_principal from .. import caldav_principal
@ -38,17 +39,22 @@ async def get_calendar(
elif len(calendar_names) > 1: elif len(calendar_names) > 1:
raise HTTPException(status_code=status.HTTP_409_CONFLICT) raise HTTPException(status_code=status.HTTP_409_CONFLICT)
principal = await caldav_principal() principal: caldav.Principal = await caldav_principal()
calendar = principal.calendar(name=calendar_names[0]) calendar = principal.calendar(name=calendar_names[0])
events = calendar.date_search( events = []
search_results = calendar.date_search(
start=datetime.now(), start=datetime.now(),
end=datetime.now() + timedelta(days=365), end=datetime.now() + timedelta(days=365),
expand=True, expand=True,
) )
return list( for event in search_results:
str(child.contents['summary'][0].value) for vevent in event.vobject_instance.contents["vevent"]:
for event in events events.append(vevent.summary.value)
for child in event.vobject_instance.contents['vevent'] events.append(vevent.description.value)
) events.append(str(vevent.dtstart.value))
events.append(str(vevent.dtend.value))
return events