34 lines
880 B
Ruby
34 lines
880 B
Ruby
require 'http'
|
|
|
|
# url = "https://static.nocoda.io/remote.php/dav/calendars/pkamin/774BE10B-AEAD-4D20-BF09-9C0FFD135E56/?export"
|
|
# a = HTTP.basic_auth(user: 'pkamin', pass: 'QDH*@8fhWekxwWjeX8MQ3H').get(url).body.to_s
|
|
|
|
# File.write('/Users/pkamin/Desktop/vacation.vcalendar', a)
|
|
|
|
a = File.read('/Users/pkamin/Desktop/vacation.vcalendar')
|
|
|
|
b = a.split("\r\n")
|
|
|
|
events = []
|
|
e = nil
|
|
|
|
puts a.length
|
|
b.each do |line|
|
|
puts line
|
|
if line == "BEGIN:VEVENT"
|
|
puts "new e"
|
|
e = Struct.new(:begin_at, :end_at)
|
|
elsif line == "END:VEVENT"
|
|
puts "end"
|
|
events << e unless e.nil?
|
|
elsif line.start_with?("DTSTART")
|
|
puts "begin"
|
|
e.begin_at = DateTime.parse(line.split(":")[1]) unless e.nil?
|
|
elsif line.start_with?("DTEND")
|
|
puts 'end'
|
|
e.end_at = DateTime.parse(line.split(":")[1]) unless e.nil?
|
|
end
|
|
end
|
|
|
|
puts events
|