www/tools/merge_cals.py

28 lines
640 B
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
from glob import glob
2018-08-15 00:49:06 +02:00
import pytz
2018-08-15 00:49:06 +02:00
import icalendar
2018-08-15 00:49:06 +02:00
2023-06-13 12:47:07 +02:00
calendars = []
2018-08-15 00:49:06 +02:00
merged = icalendar.Calendar()
2023-06-13 12:47:07 +02:00
merged.add("prodid", "-//CCCB Calendar Generator//berlin.ccc.de//")
merged.add("version", "2.0")
2023-06-13 12:47:07 +02:00
for icsfilestr in glob("public/*/**/*.ics", recursive=True):
with open(icsfilestr, "r") as icsfile:
print(f"Importing {icsfilestr}")
calendars.append(icalendar.Calendar.from_ical(icsfile.read()))
2023-06-13 12:47:07 +02:00
for calendar in calendars:
for event in calendar.subcomponents:
merged.add_component(event)
2023-06-13 12:47:07 +02:00
outfile = "static/all.ics"
with open(outfile, "wb") as f:
print(f"writing to {outfile}...")
f.write(merged.to_ical())
2018-08-15 00:49:06 +02:00