#!/usr/bin/env ruby require 'securerandom' calendarFile = 'unprocessed_calendar.ics' text=File.open("#{calendarFile}").read calendar = Array.new eventContainsUUID = false text.each_line do |line| if line.start_with?('BEGIN:VEVENT') eventContainsUID = false end if line.start_with?('PRODID') calendar.push('PRODID:-//AWS//Change Calendar 1.0//EN') calendar.push('X-CALENDAR-TYPE:DEFAULT_OPEN') calendar.push("X-WR-CALDESC:Generated by script from #{calendarFile} on #{Time.now}") next end if line.start_with?('UID') eventContainsUID = true end if line.start_with?('END:VEVENT') if !eventContainsUID calendar.push('UID:' + SecureRandom.uuid) end end calendar.push(line); end File.open("calendar.ics", "w+") do |f| calendar.each { |line| f.puts(line) } end