/
vcal2google
executable file
·186 lines (148 loc) · 3.11 KB
/
vcal2google
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/perl
use strict;
my $start;
my $end;
my $date;
my $who;
my $what;
my $where;
my $longaddrlen = -1;
sub getsumm
{
my $line = shift;
$line =~ s/"//g;
$line =~ /^SUMMARY(.*)$/;
$line =~ s/^SUMMARY.*: *//g;
$line =~ s/\\,/,/g;
$line =~ s/\\;/;/g;
$line =~ s/\n//g;
#$line =~ s/\\\\/\//g;
return($line);
}
sub getlocation
{
my $line = shift;
$line =~ s/"//g;
$line =~ /^LOCATION(.*)$/;
$line =~ s/^LOCATION.*: *//g;
$line =~ s/\\,/,/g;
$line =~ s/\\;/;/g;
$line =~ s/\n//g;
$line =~ s/\\\\/\//g;
$line =~ s/\r//g;
return($line);
}
sub gettime
{
my $line = shift; # Time line.
my $key; # Key from line.
my $val; # Value from line.
my $retstr; # Return string.
my @chron = (); # Time fields.
$line =~ s/"//g;
#
# Dig out the values from the line.
#
$line =~ /(.*?):(.*)/;
$key = $1;
$val = $2;
#
# Get the time values.
#
$val =~ s/[<>]//g;
@chron = split /T/, $val;
$chron[0] =~ s/(....)(..)(..)/$3\/$2\/$1/;
$chron[1] =~ s/(..)(..)(.*)/$1:$2/;
#
# Deal with the time zone, if present.
#
if($key =~ /TZID/) {
$key =~ /TZID="(.*)"/;
$chron[2] = $1;
}
return($chron[1]);
}
sub getdate
{
my $line = shift; # Time line.
my $key; # Key from line.
my $val; # Value from line.
my $retstr; # Return string.
my @chron = (); # Time fields.
$line =~ s/"//g;
#
# Dig out the values from the line.
#
$line =~ /(.*?):(.*)/;
$key = $1;
$val = $2;
#
# Get the time values.
#
$val =~ s/[<>]//g;
@chron = split /T/, $val;
$chron[0] =~ s/(....)(..)(..)/$2\/$3\/$1/;
$chron[1] =~ s/(..)(..)(.*)/$1:$2/;
#
# Deal with the time zone, if present.
#
if($key =~ /TZID/) {
$key =~ /TZID="(.*)"/;
$chron[2] = $1;
}
return($chron[0]);
}
sub getname
{
my $ln = shift; # Data line.
my $name; # Name from data line.
my $email; # Email address from data line.
my $retstr; # Return string.
$ln =~ s/"//g;
#
# Dig the name and email address from the line.
#
$ln =~ /CN=(.+?):/i;
$name = $1;
#
# Dig the name and email address from the line.
#
$ln =~ /:mailto:(.+)$/i;
$email = $1;
#
# Save the length of the longest email address.
#
if(length($email) > $longaddrlen) {
$longaddrlen = length($email);
}
#
# Build and return our return string.
#
if(($name eq "") && ($email eq "")) {
$retstr = "";
} else {
#$retstr = "($email)\t\t$name";
$retstr = "$name ($email)";
}
return($retstr);
}
while (<STDIN>) {
if ($_ =~ /^ORGANIZER/) {
$who = getname($_);
}
if ($_ =~ /^DTSTART/) {
$start = gettime($_);
$date = getdate($_);
}
if ($_ =~ /^DTEND/) {
$end = gettime($_);
}
if ($_ =~ /^SUMMARY/) {
$what = getsumm($_);
}
if ($_ =~ /^LOCATION/) {
$where = getlocation($_);
}
}
print "google calendar add --cal SoftKinetic \"$what with $who at $where $start $date\"\n";
system("google calendar add --cal SoftKinetic \"$what with $who at $where $start $date\"");