Last active
July 23, 2025 16:04
-
-
Save wteuber/4a823867f69fcb521ab11f4e9d514589 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# gem install icalendar | |
require 'icalendar' | |
# Open a file or pass a string to the parser | |
cal_file = File.open("/path/to/my_large_calendar.ics") | |
# Parser returns an array of calendars because a single file | |
# can have multiple calendars. | |
cals = Icalendar::Calendar.parse(cal_file) | |
cal = cals.first | |
event_slices = cal.events.each_slice(500).to_a | |
event_slices.each_with_index do |event_slice, idx| | |
cal.events.replace(event_slice) | |
File.open("events#{idx}.ics","w") {|f| f.write cal.to_ical} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment