Created
July 25, 2021 19:09
-
-
Save sigma67/7af772ecd1c5268b307a3db4229922d5 to your computer and use it in GitHub Desktop.
Fixes repeating events for Nextcloud imports from Outlook.com ics exports. Use calendar.ics for the original file and the fixed file will be calendar2.ics (both in the same folder as the script)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from icalendar import Calendar | |
import datetime | |
directory = os.path.dirname(__file__) | |
with open(os.path.join(directory, 'calendar.ics'), 'rb') as fp: | |
data = fp.read() | |
cal = Calendar.from_ical(data) | |
for event in cal.walk('vevent'): | |
if 'RRULE' in event: | |
actual_date = event['DTSTART'].dt if type(event['DTSTART'].dt) is datetime.date else event['DTSTART'].dt.date() | |
if event['RRULE']['UNTIL'][0].date() < actual_date: | |
del event['RRULE']['UNTIL'] | |
f = open(os.path.join(directory, 'calendar2.ics'), 'wb') | |
f.write(cal.to_ical()) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment