Skip to content

Instantly share code, notes, and snippets.

@dentarg
Created January 23, 2009 22:24
Show Gist options
  • Save dentarg/51236 to your computer and use it in GitHub Desktop.
Save dentarg/51236 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'rubygems'
require 'icalendar'
require 'date'
include Icalendar
icsfile = "tentor.ics"
cal = Calendar.new
cal.custom_property("X-WR-CALNAME", "Tentor")
cal.custom_property("X-WR-CALDESC", "Examinationsmoment")
file="input.txt"
f = File.open(file)
f.each do |line|
if line =~ /(\w+)\t(.+)\t(.+)\t(\d{4})-(\d{2})-(\d{2})\t (\d{1,2})\t-\t(\d{2})/
code = $1
name = $2[0..-3]
type = $3
year = $4.to_i
month = $5.to_i
day = $6.to_i
starttime = $7.to_i
endtime = $8.to_i
puts "#{code} [#{name}] #{year}-#{month}-#{day} #{starttime}-#{endtime}"
end
event_start = DateTime.civil(Time.now.year, month, day, starttime)
event_end = DateTime.civil(Time.now.year, month, day, endtime)
cal.event do
dtstart(event_start)
dtend(event_end)
summary("#{code} #{name}")
description(type)
klass("PUBLIC")
end
end
File.open(icsfile, "w").write(cal.to_ical)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment