getcal.rb 1022 Bytes
require 'net/http'

uri = URI.parse("url")

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Get.new(uri.request_uri)
request.basic_auth("user", "password")

response = http.request(request)

all = []
current = {}
response.body.each_line do |line|
  case
  when line =~ /^BEGIN:VEVENT/
    current = {}
  when line =~ /^SUMMARY/
    current[:summary] = line[line.index(':')+1..-1].strip #.gsub(/"/, '\\"')
  when line =~ /^DTSTART/
    current[:start] = line[line.index(':')+1..-1].strip
  when line =~ /^LOCATION/
    current[:location] = line[line.index(':')+1..-1].strip #.gsub(/"/, '\\"')
  when line =~ /^END:VEVENT/
    all << current
  else
    # just ignore everything else right now.
  end
end

all.each do |c|
  sdate, stime = c[:start].split('T')
  hour = '08'
  min  = '00'
  hour,min,sec = stime.scan(/../) unless stime.nil?

  puts "#{sdate} #{hour}:#{min} (#{c[:location]}) #{c[:summary]}"
end

# vim: set ft=ruby et ts=2 sw=2: