getcal.rb
1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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: