-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathics2tsv.rb
59 lines (53 loc) · 1.41 KB
/
ics2tsv.rb
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env ruby
# GoogleCalenter(ics) to TSV
require 'time'
dtnow = Time.now
if ARGV.count == 1 then
dtnow = Time.parse(ARGV[0])
end
dtlocal = dtnow
dtstart = ""
dtend = ""
description = ""
location = ""
summary = ""
STDIN.each do |line|
str = line.chomp
case str
when /^DTSTART:20/
dtstarttmp = str.gsub(/DTSTART:/,"")
year = dtstarttmp[0..3]
month = dtstarttmp[4..5]
day = dtstarttmp[6..7]
hour = dtstarttmp[9..10]
min = dtstarttmp[11..12]
sec = dtstarttmp[13..14]
dtgm = Time.gm(year, month, day, hour, min, sec)
dtlocal = dtgm + 60 * 60 * 9
dtstart = dtlocal.strftime("%Y-%m-%d %H:%M")
when /^DTEND:20/
dtstarttmp = str.gsub(/DTEND:/,"")
year = dtstarttmp[0..3]
month = dtstarttmp[4..5]
day = dtstarttmp[6..7]
hour = dtstarttmp[9..10]
min = dtstarttmp[11..12]
sec = dtstarttmp[13..14]
dtgm = Time.gm(year, month, day, hour, min, sec)
dtlocal = dtgm + 60 * 60 * 9
dtend = dtlocal.strftime("%Y-%m-%d %H:%M")
when /^DESCRIPTION:/
description = str.gsub(/DESCRIPTION:/,"")
when /^LOCATION:/
location = str.gsub(/LOCATION:/,"")
when /^ /
description = description + str.gsub(/^ /,"")
when /^SUMMARY:/
summary = str.gsub(/SUMMARY:/,"")
when /END:VEVENT/
if dtlocal > dtnow then
print dtstart,"\t",dtend,"\t",summary,"\t",location,"\t",description,"\n"
dtlocal = dtnow
end
end
end