File: examples.py

package info (click to toggle)
python-recurring-ical-events 3.8.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,584 kB
  • sloc: python: 4,476; makefile: 84
file content (29 lines) | stat: -rw-r--r-- 749 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Functionality for smaller examples."""

import icalendar

from recurring_ical_events.constants import CALENDARS


def example_calendar(name: str = "") -> icalendar.Calendar:
    """Return an example calendar.

    Args:
        name (str): The name of the example file.

    Returns:
        icalendar.cal.Calendar: The parsed calendar example.
    """
    if not name.endswith(".ics"):
        name += ".ics"
    path = CALENDARS / name
    try:
        return icalendar.Calendar.from_ical(path.read_bytes())
    except FileNotFoundError:
        raise ValueError(  # noqa: B904
            f"File {name!r} not found. "
            f"Use one of {', '.join(p.name for p in CALENDARS.glob('*.ics'))!r}."
        )


__all__ = ["example_calendar"]