calendar-fetcher/helper.py

52 lines
1.6 KiB
Python

"""Script to fetch the calendar names and colors"""
import caldav
import caldav.elements.ical # for calendarColor
import pprint
# Configuration for the CalDAV server
url = "https://cloud.ruinelli.ch/remote.php/dav/principals/users/"
userN = "gruinelli"
passW = "attgigoc1"
def fetch_calendar():
numberOfDaysToShow = 5
# excludedCalendars = ['todo', 'todogemeinsam', 'contact_birthdays', 'geburtstage', 'infos']
excludedCalendars = ['ToDo', 'ToDo Gemeinsam', 'Geburtstage von Kontakten', 'Geburtstage', 'Infos']
# excludedCalendars = ['todo', 'todogemeinsam', 'contact_birthdays', 'geburtstage', 'gemeinsam', 'evtermine_shared_by_anita', 'jael']
# excludedCalendars = ['gemeinsam', 'contact_birthdays', 'geburtstage']
client = caldav.DAVClient(url=url, username=userN, password=passW)
principal = client.principal()
calendars = principal.calendars()
#print(calendars)
#print("")
calendarNames = (str(calendars).replace("Calendar(https://cloud.ruinelli.ch/remote.php/dav/calendars/gruinelli/", "").
replace(")", "").replace("/", "").replace("[", "").replace("]", "").
split(","))
#print(calendarNames)
#print("")
metaData = []
i = 0
for calendar in calendars:
#print(calendar)
data = {}
data["calendarName"] = calendarNames[i]
i += 1
data["displayname"] = list(calendar.get_properties([caldav.dav.DisplayName()]).values())[0]
data["color"] = list(calendar.get_properties([caldav.elements.ical.CalendarColor()]).values())[0]
metaData.append(data)
print("")
pprint.pprint(metaData)
if __name__ == '__main__':
fetch_calendar()