From: Andrew Ruthven Date: Fri, 4 Nov 2016 10:10:56 +0000 (+1300) Subject: Take a Free/Busy feed and generate an iCal file X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05176460b7da9817d0ac5d6c4ecb23e165ea5ae7;p=calendar-busy.git Take a Free/Busy feed and generate an iCal file --- 05176460b7da9817d0ac5d6c4ecb23e165ea5ae7 diff --git a/calendar-busy.pl b/calendar-busy.pl new file mode 100755 index 0000000..eda87d7 --- /dev/null +++ b/calendar-busy.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl -w + +use v5.10; +use LWP; +use LWP::UserAgent; +use Data::ICal; +use Data::ICal::Entry::Event; + + +my $url = 'http://calendar.etc.gen.nz/freebusy.php/susanne'; + +my $ua = LWP::UserAgent->new(); + +$ua->default_header('Accept' => 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'); +$ua->default_header('Accept-Language' => 'en-us,en;q=0.5'); +$ua->default_header('Accept-Charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'); +$ua->default_header('Accept-Encoding' => 'gzip,deflate'); +$ua->default_header('Content-Type' => 'text/xml'); + +my $request = HTTP::Request->new('GET', $url, undef); +my $response = $ua->request($request); + +die "Failed to get response from server: " . $response->status_line + unless $response->is_success; + +my $freebusy = $response->decoded_content; + +my $calendar = Data::ICal->new(); + +for my $line (split(/\n/, $freebusy)) { + next unless $line =~ /^FREEBUSY/; + + + (my $start, $end) = $line =~ /^FREEBUSY:([0-9TZ]+)\/([0-9TZ]+)/; + my $event = Data::ICal::Entry::Event->new(); + $event->add_properties( + summary => 'Busy', + dtstart => $start, + dtend => $end, + ); + + $calendar->add_entry($event); + $count++; +} + +say $calendar->as_string; + +