Last active
August 29, 2015 13:56
-
-
Save ukasiu/9288878 to your computer and use it in GitHub Desktop.
Enrollme googlecalendar export improver
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
#!/usr/bin/env ruby | |
# Skrypcik konwerujący zbugowany eksport do GoogleCalendar z Enrollme | |
# 9:35 - 11:05 -> 9:30 - 11:00 | |
# 12:50 - 14:20 -> 12:45 - 14:15 | |
# 14:40 - 16:10 -> 14:30 - 16:00 | |
# 17:50 - 19:20 -> 17:45 - 19:15 | |
TIME_MAPPING = { | |
'(DTSTART:.+)(T093000)(Z)' => 'T093500', | |
'(DTEND:.+)(T110000)(Z)' => 'T110500', | |
'(DTSTART:.+)(T124500)(Z)' => 'T125000', | |
'(DTEND:.+)(T141500)(Z)' => 'T142000', | |
'(DTSTART:.+)(T143000)(Z)' => 'T144000', | |
'(DTEND:.+)(T160000)(Z)' => 'T161000', | |
'(DTSTART:.+)(T174500)(Z)' => 'T175000', | |
'(DTEND:.+)(T191500)(Z)' => 'T192000' | |
} | |
if ARGV.count != 2 | |
puts "usage: ./convert.rb input_file.ics output_file.ics" | |
exit | |
end | |
input_file = ARGV[0] | |
output_file = ARGV[1] | |
input_file_content = File.read(input_file) | |
#recurring | |
input_file_content.gsub!('END:VEVENT',"RRULE:FREQ=WEEKLY;UNTIL=20140721T093000Z\nEND:VEVENT") | |
TIME_MAPPING.each do |k,v| | |
input_file_content.gsub!(/#{k}/,'\1' + v +'\3') | |
end | |
input_file_content.gsub!(/(DT.+:.+)(T\d{6})(Z)/,'\1\2') | |
File.write(output_file,input_file_content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment