-
Notifications
You must be signed in to change notification settings - Fork 0
/
ingolstadt-kulturamt.pl
executable file
·62 lines (48 loc) · 1.7 KB
/
ingolstadt-kulturamt.pl
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
#!/usr/bin/perl
# AGPLv3
use strict;
use WWW::Mechanize;
use DateTime;
use Data::ICal;
use Data::ICal::Entry::Event;
use utf8;
use warnings;
# Kulturamt Ingolstadt already provides basic information in ics format, but only for single months
my $calendar=Data::ICal->new();
$calendar->add_properties(method=>"PUBLISH",
"X-PUBLISHED-TTL"=>"P1D",
"X-WR-CALNAME"=>"Kulturamt Ingolstadt",
"X-WR-CALDESC"=>"Kulturamt Ingolstadt Veranstaltungen");
# avoid "wide character" warnings
binmode STDOUT, ":utf8";
my $mech=WWW::Mechanize->new();
my $date=DateTime->now;
my $MAXMONTHS=12;
for (my $month=0;$month<$MAXMONTHS;$month++) {
my $url="https://www.kulturamt-ingolstadt.de/veranstaltungen/monat/".$date->strftime("%Y-%m")."/?ical=1";
$mech->get($url) or die($!);
# Data::ICal::Entry does not understand REFRESH-INTERVAL, so filter that out
my @filtered;
my @lines=split /\n/, $mech->content();
foreach (@lines) {
push(@filtered,$_) unless $_=~/^refresh-interval/i;
}
my $kaCalendar=Data::ICal->new(data=>join("\n", @filtered));
# if there are no events this month, no ical without entries but unfortunately an empty document is returned
next unless $kaCalendar;
foreach my $entry (@{$kaCalendar->entries}) {
$calendar->add_entry($entry);
# Add URL to DESCRIPTION
my ($url, $description);
if (exists($entry->properties->{'url'})) {
$url=$entry->properties->{'url'}->[0]->value;
if (exists($entry->properties->{'description'})) {
$description=$entry->properties->{'description'}->[0]->value;
}
$entry->add_property(description => join("\n", ($description, $url)));
}
}
$date->add(months=>1);
}
print $calendar->as_string;