www/tools/merge_cals.py

28 lines
605 B
Python
Raw 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
cals = []
merged = icalendar.Calendar()
merged.add('prodid', '-//CCCB Calendar Generator//berlin.ccc.de//')
2018-08-15 00:49:06 +02:00
merged.add('version', '2.0')
2018-08-15 00:49:06 +02:00
for icsfilestr in glob('public/*/**/*.ics', recursive=True):
with open(icsfilestr, 'r') as icsfile:
2018-08-15 00:49:06 +02:00
print('Importing', icsfilestr)
cals.append(icalendar.Calendar.from_ical(icsfile.read()))
for cal in cals:
for e in cal.subcomponents:
merged.add_component(e)
2018-08-15 00:49:06 +02:00
outfile = 'static/all.ics'
with open(outfile, 'wb') as f:
2018-08-15 00:49:06 +02:00
print(f'writing to {outfile}...')
f.write(merged.to_ical())
2018-08-15 00:49:06 +02:00