2018-07-13 00:03:33 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from glob import glob
|
2018-08-15 00:49:06 +02:00
|
|
|
|
2018-07-13 00:03:33 +02:00
|
|
|
import pytz
|
2018-08-15 00:49:06 +02:00
|
|
|
import icalendar
|
2018-07-13 00:03:33 +02:00
|
|
|
|
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")
|
2018-07-13 00:03:33 +02:00
|
|
|
|
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()))
|
2018-07-13 00:03:33 +02:00
|
|
|
|
2023-06-13 12:47:07 +02:00
|
|
|
for calendar in calendars:
|
|
|
|
for event in calendar.subcomponents:
|
|
|
|
merged.add_component(event)
|
2018-07-13 00:03:33 +02:00
|
|
|
|
2023-06-13 12:47:07 +02:00
|
|
|
outfile = "static/all.ics"
|
|
|
|
with open(outfile, "wb") as f:
|
|
|
|
print(f"writing to {outfile}...")
|
2018-07-13 00:03:33 +02:00
|
|
|
f.write(merged.to_ical())
|
2018-08-15 00:49:06 +02:00
|
|
|
|