Nextcloud Calendar: Create a calendar event
One script reply has been approved by the moderators Verified

Create an event in a calendar in Nextcloud calendar.

Created by marcel klehr12 589 days ago Picked 5 times
Submitted by nextcloud Python3
Verified 6 days ago
1
import caldav
2
import base64
3
import datetime
4

5
# You can import any PyPi package.
6
# See here for more info: https://www.windmill.dev/docs/advanced/dependencies_in_python
7

8
# you can use typed resources by doing a type alias to dict
9
nextcloud = dict
10
datetime = dict
11

12

13
def main(
14
    Nextcloud: nextcloud,
15
    calendarName: str,
16
    event_start: datetime,
17
    event_end: datetime,
18
):
19
    headers = {}
20

21
    with caldav.DAVClient(
22
        url=Nextcloud["baseUrl"] + "/remote.php/dav/calendars/" + Nextcloud["userId"] + "/",
23
        username=Nextcloud["userId"],
24
        password=Nextcloud["token"],
25
        headers=headers,
26
    ) as client:
27
        my_principal = client.principal()
28
        calendar = next(
29
            filter(
30
                lambda calendar: calendar.name == calendarName, my_principal.calendars()
31
            )
32
        )
33
        if calendar is None:
34
            raise ValueError("Could not find calendar by the name you provided")
35

36
        my_event = calendar.save_event(
37
            dtstart=event_start,
38
            dtend=event_end,
39
            summary="Do the needful",
40
        )
41
        return my_event
42

43

Other submissions