33import calendar
44from dataclasses import dataclass
55from datetime import datetime
6+ from functools import partial
7+ from typing import Callable
68
79from ..constants import LOGGER , URL
810from ..helpers .request import Request
@@ -21,7 +23,7 @@ class Calendar:
2123 events : list[Calendar] or list[dict[str, any]]
2224 Use `events` to access the most important properties.
2325 It is either in `Calendar` or `JSON` format.
24- When it is in JSON format it has all including unnecessary properties.
26+ When it is in JSON format it has all, including unnecessary ones, properties.
2527 """
2628
2729 @dataclass
@@ -43,6 +45,9 @@ class Event:
4345 Could also exceed the calendars start and end.
4446 whole_day : bool
4547 Does it happen the whole day or only between a specific time.
48+ responsible : Callable
49+ The person who is responsible for this event.
50+ You need to call this first, then it returns (hopefully) a string.
4651 """
4752
4853 title : str
@@ -51,12 +56,38 @@ class Event:
5156 start : datetime
5257 end : datetime
5358 whole_day : bool
59+ responsible : Callable
5460
5561 start : datetime
5662 end : datetime
5763 events : list [Event ] | list [dict [str , any ]] = None
5864
5965
66+ def _get_responsible (id : str ) -> str :
67+ """Get the responsible person of an event.
68+
69+ Parameters
70+ ----------
71+ id : str
72+ The id of the calendar event, if None just return None.
73+
74+ Returns
75+ -------
76+ str
77+ """
78+ if not id :
79+ return None
80+
81+ data = {
82+ "f" : "getEvent" ,
83+ "id" : id ,
84+ }
85+
86+ response = Request .post (URL .calendar , data = data )
87+
88+ return response .json ()["properties" ]["verantwortlich" ]
89+
90+
6091def _get_calendar_month (json : bool = False ) -> Calendar :
6192 """Use the _get_calendar() function but only returns all events of the current month.
6293
@@ -140,13 +171,24 @@ def _get_calendar(start: datetime, end: datetime, json: bool = False) -> Calenda
140171 # Get JSON and map it to `Calendar` data class.
141172 calendar = Calendar (start , end , events = [])
142173 for data in calendar_raw_data .json ():
174+ # If data["Verantwortlich"] doesn't even exist, we can just return None when called.
175+ try :
176+ responsible = (
177+ partial (_get_responsible , id = data ["Id" ])
178+ if data ["Verantwortlich" ]
179+ else partial (_get_responsible , id = None )
180+ )
181+ except KeyError :
182+ responsible = partial (_get_responsible , id = None )
183+
143184 calendar_data = Calendar .Event (
144185 title = data ["title" ],
145186 description = data ["description" ],
146187 place = data ["Ort" ],
147188 start = datetime .strptime (data ["Anfang" ], "%Y-%m-%d %H:%M:%S" ),
148189 end = datetime .strptime (data ["Ende" ], "%Y-%m-%d %H:%M:%S" ),
149190 whole_day = data ["allDay" ],
191+ responsible = responsible ,
150192 )
151193 calendar .events .append (calendar_data )
152194
0 commit comments