]>
git.refcnt.org Git - lugs.git/blob - make-ical/make-ical.pl
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 # Author: Steven Schubiger <stsc@refcnt.org>
18 # Last modified: Fri Apr 17 23:12:38 CEST 2015
27 base_url
=> 'http://www.lugs.ch/lugs/termine',
28 input
=> './termine.txt',
34 mkdir $Config->{ical_dir
} unless -e
$Config->{ical_dir
};
36 my $ical = LUGS
::Termine
::ICal
->new;
37 $ical->process_events;
40 package LUGS
::Termine
::ICal
;
42 use constant true
=> 1;
43 use constant false
=> 0;
46 use Data
::ICal
::Entry
::Event
();
48 use Encode
qw(encode);
50 use HTML
::Entities
qw(decode_entities);
51 use LUGS
::Events
::Parser
();
64 my $parser = LUGS
::Events
::Parser
->new($Config->{input
}, {
69 fields
=> [ qw(location) ],
71 rewrite
=> '$TEXT ($HREF)',
72 fields
=> [ qw(more) ],
75 strip_text
=> [ 'mailto:' ],
78 while (my $event = $parser->next_event) {
79 my $year = $event->get_event_year;
80 my $month = $event->get_event_month;
81 my $day = $event->get_event_day;
85 if ($event->get_event_time =~ /^(\d+:\d+) (?:\s+ - \s+ (\d+:\d+))?$/x) {
86 @time{qw(start_hour start_min)} = split /\:/, $1;
88 @time{qw(end_hour end_min)} = split /\:/, $2;
91 @time{qw(end_hour end_min)} = @time{qw(start_hour start_min)};
95 %time = map { $_ => 0 } qw(start_hour start_min end_hour end_min);
98 $self->{calendar
} = Data
::ICal
->new;
99 my $ical_event = Data
::ICal
::Entry
::Event
->new;
101 my $location = $event->get_event_location;
102 my $summary = $event->get_event_title;
103 my $anchor = $event->get_event_anchor;
104 my $more = $event->get_event_more;
106 $location =~ s/\(.+?\)//g;
107 $more =~ s/<.+?>//g if defined $more;
109 sub { decode_entities
($_) foreach @_ }->($location, $summary, defined $more ?
$more : ());
110 sub { $_ = encode
('UTF-8', $_) foreach @_ }->($location, $summary, defined $more ?
$more : ());
112 my $offset = $Config->{offset
} ?
$Config->{offset
} : ((localtime)[8] ?
'+0200' : '+0100');
114 $ical_event->add_properties(
115 dtstamp
=> Date
::ICal
->new->ical,
116 dtstart
=> Date
::ICal
->new(
120 hour
=> $time{start_hour
},
121 min
=> $time{start_min
},
125 dtend
=> Date
::ICal
->new(
129 hour
=> $time{end_hour
},
130 min
=> $time{end_min
},
134 location
=> $location,
137 description
=> $more,
139 uid
=> "${anchor}\@lugs.ch",
140 url
=> join '#', ($Config->{base_url
}, $anchor),
143 $self->{calendar
}->add_entry($ical_event);
144 $self->save_ical($anchor);
153 my $ics_file = $file . '.ics';
154 my $ics_path = File
::Spec
->catfile($Config->{ical_dir
}, $ics_file);
156 open(my $fh, '>', $ics_path) or die "Cannot write $ics_path: $!\n";
157 print {$fh} do { local $_ = $self->{calendar
}->as_string;