From 559803ac0e07222347942637a19faf190365405b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Sun, 4 Sep 2022 14:14:22 +0000 Subject: [PATCH] use properties correctly --- api/ovdashboard_api/routers/calendar.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/api/ovdashboard_api/routers/calendar.py b/api/ovdashboard_api/routers/calendar.py index 85493cb..dab9de2 100644 --- a/api/ovdashboard_api/routers/calendar.py +++ b/api/ovdashboard_api/routers/calendar.py @@ -1,6 +1,7 @@ from datetime import datetime, timedelta from typing import Iterator +import caldav from fastapi import APIRouter, Depends, HTTPException, status from .. import caldav_principal @@ -38,17 +39,22 @@ async def get_calendar( elif len(calendar_names) > 1: 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]) - events = calendar.date_search( + events = [] + + search_results = calendar.date_search( start=datetime.now(), end=datetime.now() + timedelta(days=365), expand=True, ) - return list( - str(child.contents['summary'][0].value) - for event in events - for child in event.vobject_instance.contents['vevent'] - ) + for event in search_results: + for vevent in event.vobject_instance.contents["vevent"]: + events.append(vevent.summary.value) + events.append(vevent.description.value) + events.append(str(vevent.dtstart.value)) + events.append(str(vevent.dtend.value)) + + return events