#!/usr/bin/ruby

if ARGV.length < 1
	puts "usage: ./convert_events.rb in.csv [out.csv]"
	puts "outputs to stdin, if no output file given"
	exit
end

out = nil

if ARGV[1]
	out = File.open(ARGV[1], 'w')
end

ignoreFirstRow = true
#i = 0

IO.foreach(ARGV[0]) { |row|
	if not ignoreFirstRow
		column = row.split(';')[0..7]
		if column[0] != ''
			day, month = column[0].split('.')
			hour, minute, second = column[1].split(':')
			timestamp = Time.mktime(2012, month, day, hour, minute, second).to_i
			newRow = [timestamp, column[5], column[2], column[3], column[6], column[7]].join "\t"
			if out.nil?
				puts newRow
			else
				f.write newRow+"\n"
			end
		end
	end
	ignoreFirstRow = false
#	i += 1
#	break if i == 100
}
