-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreadcal.pl
More file actions
executable file
·67 lines (59 loc) · 1.14 KB
/
readcal.pl
File metadata and controls
executable file
·67 lines (59 loc) · 1.14 KB
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
#!/usr/bin/perl -w
use warnings;
use strict;
# function to read an ics file
sub readCalendar
{
my $event = {};
my $calendar = {};
my $keyword = "nothing";
open (MYFILE, shift);
while (<MYFILE>)
{
chomp;
if ( $_ =~ /BEGIN:VEVENT/ )
{
# here starts an event -> empty the events hash
$event = {};
next;
}
if ( $_ =~ /END:VEVENT/ )
{
# end of an even -> store event in calendar
$calendar->{$event->{'UID'}} = $event;
next;
}
if ( $_ =~ /^[A-Z]/)
{
my @values = split(':', $_);
$keyword = shift @values;
# $cur = value for $keyword
my $cur = join (':', @values);
$cur =~ s/^\s+//;
$cur =~ s/\s+$//;
$event->{$keyword} = $cur;
}
else
{
# if this starts with smth ![A-Z] -> append the line to the last key
my $cur = $_;
$cur =~ s/^\s+//;
$cur =~ s/\s+$//;
$event->{$keyword} = $event->{$keyword} . $cur;
}
}
close (MYFILE);
return $calendar;
}
# use it
my $cal = readCalendar "/path/to/calendar";
# delete this.
foreach my $key (keys %$cal)
{
print "FOUND EVENT:\n";
foreach my $k (keys $cal->{$key})
{
print "$k => ".$cal->{$key}->{$k}."\n";
}
print "\n\n";
}