diff options
Diffstat (limited to 'bin/events2md.pl')
-rwxr-xr-x | bin/events2md.pl | 122 |
1 files changed, 6 insertions, 116 deletions
diff --git a/bin/events2md.pl b/bin/events2md.pl index c7cf572..d0dc9b5 100755 --- a/bin/events2md.pl +++ b/bin/events2md.pl @@ -5,9 +5,9 @@ use utf8; use open qw(:std :encoding(UTF-8)); use autodie; use Feature::Compat::Try; -use Feature::Compat::Class 0.07; use FindBin qw($Bin); +use lib "$Bin/../lib"; use POSIX qw(locale_h); use locale; @@ -21,11 +21,12 @@ use Log::Any::Adapter; use URI; use IO::Prompter; use Cal::DAV; -use Data::ICal::DateTime; use DateTime; use Path::Tiny; use Text::Xslate; +use Object::Groupware::Calendar; + if ( IO::Interactive::Tiny::is_interactive() ) { Log::Any::Adapter->set( 'Screen', default_level => 'info' ); } @@ -42,117 +43,6 @@ $CALENDAR_URI ||= shift @ARGV $OUTPUT_FILE = shift @ARGV if @ARGV; -class Calendar { - field $log = Log::Any->get_logger; - - # borrow from Data::ICal::new() signature - field $data : param = undef; - field $filename : param = undef; - - ADJUST { - if ($data) { - if ( $data isa Data::ICal ) { } - else { $data = Data::ICal->new( data => $data ) } - } - elsif ($filename) { $data = Data::ICal->new( filename => $filename ) } - - if ( $log->is_trace ) { - use DDP; - p $data; - } - } - - # mimick Data::ICal::DateTime::events() signature - method events ( $set = undef, $period = undef ) - { - $log->infof( - 'will pick events between %s and %s', - $set->start, $set->end - ) if $set; - - my @events = map { Event->new( entry => $_ ) } sort { - $a->start->compare( $b->start ) - || $a->start->compare( $b->start ) - || $a->summary cmp $b->summary - } $data->events( $set || (), $period || () ); - - return @events; - } -} - -class Event { - field $log = Log::Any->get_logger; - - field $entry : param; - - field $begin : reader = $entry->start; - field $date_begin : reader = $begin->strftime('%A %e. %B'); - field $time_begin : reader = $begin->strftime('%k.%M'); - field $end : reader = $entry->end; - field $date_end : reader; - field $time_end : reader; - field $datespan : reader; - field $timespan : reader; - field $time_brief : reader; - field $summary : reader = $entry->summary; - field $description : reader = $entry->description; - field $location : reader = $entry->_simple_property('location'); - field $price : reader; - field @attendees; - field @attachments; - - ADJUST { - if ( defined $end ) { - $date_end = $end->strftime('%A %e. %B'); - $time_end = $end->strftime('%k.%M'); - } - $datespan - = ( defined $end and $date_end ne $date_begin ) - ? ucfirst("$date_begin - $date_end") - : ucfirst("$date_begin"); - $timespan - = ( defined $end and not $entry->all_day ) - ? ucfirst("$date_begin kl. $time_begin-$time_end") - : undef; - $time_brief - = $entry->all_day - ? $datespan - : ucfirst("$date_begin kl. $time_begin"); - $description =~ s/\n\n[Pp]ris:\s*((?!\n).+)\s*\z//m; - $price = $1; - - if ( $entry->property('attendee') ) { - for ( @{ $entry->property('attendee') } ) { - push @attendees, $_->parameters->{'CN'} - || $_->value =~ s/^mailto://r; - } - } - if ( $entry->property('attach') ) { - for ( @{ $entry->property('attach') } ) { - my $uri; - try { $uri = URI->new( $_->value ) } - catch ($e) { - $log->errorf( 'failed to parse URI %s: %s', $uri, $e ); - next; - } - $uri->authority and $uri->host - or next; - push @attachments, $uri; - } - } - - if ( $log->is_trace ) { - use DDP; - p $entry; - p $begin; - p $end; - } - } - - method attendees { !!@attendees ? [@attendees] : undef } - method attachments { !!@attachments ? [@attachments] : undef } -} - # use system locale to format DateTime objects parsed from iCal data DateTime->DefaultLocale( setlocale(LC_TIME) ); @@ -207,7 +97,7 @@ if ( $base_uri->scheme eq 'http' or $base_uri->scheme eq 'https' ) { ); $session->get($calendar_uri) if $calendar_uri; - $calendar = Calendar->new( data => $session->cal ); + $calendar = Object::Groupware::Calendar->new( data => $session->cal ); } elsif ( $base_uri->scheme eq 'file' ) { defined $base_uri->file @@ -218,12 +108,12 @@ elsif ( $base_uri->scheme eq 'file' ) { $log->debug('parse local calendar data...'); my $path = path( $base_uri->file ); if ( $path->is_file ) { - $calendar = Calendar->new( filename => "$path" ); + $calendar = Object::Groupware::Calendar->new( filename => "$path" ); } else { my $data; $path->visit( sub { $data .= $_->slurp_raw if $_->is_file } ); - $calendar = Calendar->new( data => $data ); + $calendar = Object::Groupware::Calendar->new( data => $data ); } } if ( $log->is_trace ) { |