Debian Codegraph @

recurring_ical_events/examples.py

raw symbols SCIP
1 """Functionality for smaller examples."""
2
3 import icalendar
4
5 from recurring_ical_events.constants import CALENDARS
6
7
8 def example_calendar(name: str = "") -> icalendar.Calendar:
9 """Return an example calendar.
10
11 Args:
12 name (str): The name of the example file.
13
14 Returns:
15 icalendar.cal.Calendar: The parsed calendar example.
16 """
17 if not name.endswith(".ics"):
18 name += ".ics"
19 path = CALENDARS / name
20 try:
21 return icalendar.Calendar.from_ical(path.read_bytes())
22 except FileNotFoundError:
23 raise ValueError( # noqa: B904
24 f"File {name!r} not found. "
25 f"Use one of {', '.join(p.name for p in CALENDARS.glob('*.ics'))!r}."
26 )
27
28
29 __all__ = ["example_calendar"]