]>
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: Wed 09 Jun 2021 10:05:08 PM CEST
27 base_url
=> 'https://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
();
50 use LUGS
::Events
::Parser
();
63 my $parser = LUGS
::Events
::Parser
->new($Config->{input
}, {
68 fields
=> [ qw(location) ],
70 rewrite
=> '$TEXT ($HREF)',
71 fields
=> [ qw(more) ],
74 strip_text
=> [ 'mailto:' ],
77 while (my $event = $parser->next_event) {
78 my $year = $event->get_event_year;
79 my $month = $event->get_event_month;
80 my $day = $event->get_event_day;
84 if ($event->get_event_time =~ /^(\d+:\d+) (?:\s+ - \s+ (\d+:\d+))?$/x) {
85 @time{qw(start_hour start_min)} = split /\:/, $1;
87 @time{qw(end_hour end_min)} = split /\:/, $2;
90 @time{qw(end_hour end_min)} = @time{qw(start_hour start_min)};
94 %time = map { $_ => 0 } qw(start_hour start_min end_hour end_min);
97 $self->{calendar
} = Data
::ICal
->new;
98 my $ical_event = Data
::ICal
::Entry
::Event
->new;
100 my $location = $event->get_event_location;
101 my $summary = $event->get_event_title;
102 my $anchor = $event->get_event_anchor;
103 my $more = $event->get_event_more;
105 $location =~ s/\(.+?\)//g;
106 $more =~ s/<.+?>//g if defined $more;
110 my ($hour, $minute) = @_;
111 return $Config->{offset
} if $Config->{offset
};
112 my $dt = DateTime
->new(
118 time_zone
=> 'Europe/Zurich',
120 return $dt->is_dst() ?
'+0200' : '+0100';
122 $ical_event->add_properties(
123 dtstamp
=> Date
::ICal
->new->ical,
124 dtstart
=> Date
::ICal
->new(
128 hour
=> $time{start_hour
},
129 min
=> $time{start_min
},
131 offset
=> $get_offset->(@time{qw(start_hour start_min)}),
133 dtend
=> Date
::ICal
->new(
137 hour
=> $time{end_hour
},
138 min
=> $time{end_min
},
140 offset
=> $get_offset->(@time{qw(end_hour end_min)}),
142 location
=> $location,
145 description
=> $more,
147 uid
=> "${anchor}\@lugs.ch",
148 url
=> join '#', ($Config->{base_url
}, $anchor),
151 $self->{calendar
}->add_entry($ical_event);
152 $self->save_ical($anchor);
161 my $ics_file = $file . '.ics';
162 my $ics_path = File
::Spec
->catfile($Config->{ical_dir
}, $ics_file);
164 open(my $fh, '>', $ics_path) or die "Cannot write $ics_path: $!\n";
165 print {$fh} do { local $_ = $self->{calendar
}->as_string;